org.xwiki.job
Class AbstractJob<R extends Request>

java.lang.Object
  extended by org.xwiki.job.AbstractJob<R>
Type Parameters:
R - the request type associated to the job
All Implemented Interfaces:
Job

@InstantiationStrategy(value=PER_LOOKUP)
public abstract class AbstractJob<R extends Request>
extends Object
implements Job

Base class for Job implementations.

Since:
4.0M1
Version:
$Id$

Field Summary
protected  ComponentManager componentManager
          Component manager.
protected  JobContext jobContext
          Used to set the current context.
protected  org.slf4j.Logger logger
          The logger to log.
protected  LoggerManager loggerManager
          Used to isolate job related log.
protected  org.xwiki.observation.ObservationManager observationManager
          Used to send extensions installation and upgrade related events.
protected  R request
          The job request.
protected  org.xwiki.job.internal.AbstractJobStatus<R> status
           
protected  org.xwiki.job.internal.JobStatusStorage storage
          Used to store the results of the jobs execution.
 
Constructor Summary
AbstractJob()
           
 
Method Summary
protected  R castRequest(Request request)
          Should be overridden if R is not Request.
protected  org.xwiki.job.internal.AbstractJobStatus<R> createNewStatus(R request)
           
 R getRequest()
           
 JobStatus getStatus()
           
protected  void jobFinished(Exception exception)
          Called when the job is done.
protected  void jobStarting()
          Called when the job is starting.
 void join()
          Causes the current thread to wait until this job has FINSHED state.
 boolean join(long time, TimeUnit unit)
          Causes the current thread to wait until this job has FINSHED state.
protected  void notifyPopLevelProgress()
          Pop progression level.
protected  void notifyPushLevelProgress(int steps)
          Push new progression level.
protected  void notifyStepPropress()
          Next step.
protected abstract  void start()
          Should be implemented by Job implementations.
 void start(Request request)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xwiki.job.Job
getType
 

Field Detail

componentManager

@Inject
protected ComponentManager componentManager
Component manager.


observationManager

@Inject
protected org.xwiki.observation.ObservationManager observationManager
Used to send extensions installation and upgrade related events.


loggerManager

@Inject
protected LoggerManager loggerManager
Used to isolate job related log.


storage

@Inject
protected org.xwiki.job.internal.JobStatusStorage storage
Used to store the results of the jobs execution.


logger

@Inject
protected org.slf4j.Logger logger
The logger to log.


jobContext

@Inject
protected JobContext jobContext
Used to set the current context.


request

protected R extends Request request
The job request.


status

protected org.xwiki.job.internal.AbstractJobStatus<R extends Request> status
See Also:
getStatus()
Constructor Detail

AbstractJob

public AbstractJob()
Method Detail

getRequest

public R getRequest()
Specified by:
getRequest in interface Job
Returns:
the job request

getStatus

public JobStatus getStatus()
Specified by:
getStatus in interface Job
Returns:
the status of the job

start

public void start(Request request)
Specified by:
start in interface Job
Parameters:
request - start the job with provided request

jobStarting

protected void jobStarting()
Called when the job is starting.


jobFinished

protected void jobFinished(Exception exception)
Called when the job is done.

Parameters:
exception - the exception throw during execution of the job

castRequest

protected R castRequest(Request request)
Should be overridden if R is not Request.

Parameters:
request - the request
Returns:
the request in the proper extended type

createNewStatus

protected org.xwiki.job.internal.AbstractJobStatus<R> createNewStatus(R request)
Parameters:
request - contains information related to the job to execute
Returns:
the status of the job

notifyPushLevelProgress

protected void notifyPushLevelProgress(int steps)
Push new progression level.

Parameters:
steps - number of steps in this new level

notifyStepPropress

protected void notifyStepPropress()
Next step.


notifyPopLevelProgress

protected void notifyPopLevelProgress()
Pop progression level.


start

protected abstract void start()
                       throws Exception
Should be implemented by Job implementations.

Throws:
Exception - errors during job execution

join

public void join()
          throws InterruptedException
Description copied from interface: Job
Causes the current thread to wait until this job has FINSHED state.

Specified by:
join in interface Job
Throws:
InterruptedException - if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.

join

public boolean join(long time,
                    TimeUnit unit)
             throws InterruptedException
Description copied from interface: Job
Causes the current thread to wait until this job has FINSHED state.

Specified by:
join in interface Job
Parameters:
time - the maximum time to wait
unit - the time unit of the time argument
Returns:
false if the waiting time detectably elapsed before return from the method, else true
Throws:
InterruptedException - if the current thread is interrupted (and interruption of thread suspension is supported)


Copyright © 2004-2012 XWiki. All Rights Reserved.