Package org.openforis.concurrency
Class Job
- java.lang.Object
-
- org.openforis.concurrency.Worker
-
- org.openforis.concurrency.Job
-
public abstract class Job extends Worker
Synchronously executes a series of Tasks in order.- Author:
- M. Togna, S. Ricci
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openforis.concurrency.Worker
Worker.Status
-
-
Constructor Summary
Constructors Constructor Description Job()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidabort()protected <T extends Worker>
TaddTask(Class<T> type)Creates and adds a task of the specified type.protected <T extends Worker>
voidaddTask(T task)Throws IllegalStateException if invoked after run() is calledprotected <C extends Collection<? extends Worker>>
voidaddTasks(C tasks)protected abstract voidbuildTasks()Creates and adds tasks to this job.protected <T extends Worker>
TcreateTask(Class<T> type)protected voidexecute()Runs each contained task in order.WorkergetCurrentTask()intgetCurrentTaskIndex()JobManagergetJobManager()intgetProgressPercent()List<Worker>getTasks()protected booleanhasTaskToRun()protected voidinitializeInternalVariables()Builds all the tasks.protected voidinitializeTask(Worker task)Called before task execution.protected WorkernextTask()protected voidonTaskCompleted(Worker task)Called when the task ends its execution with the statusWorker.Status.COMPLETEDprotected voidonTaskEnd(Worker task)Called when the task ends its execution.protected voidonTaskFailed(Worker task)voidrelease()Releases the resource used during the executionprotected voidrunTask(Worker task)voidsetJobManager(JobManager jobManager)-
Methods inherited from class org.openforis.concurrency.Worker
addStatusChangeListener, afterExecute, afterExecuteInternal, beforeExecute, beforeExecuteInternal, changeStatus, createInternalVariables, destroy, getDuration, getEndTime, getErrorMessage, getErrorMessageArgs, getId, getLastException, getName, getStartTime, getStatus, getWeight, initialize, isAborted, isCompleted, isEnded, isFailed, isPending, isRunning, logDebug, logError, logInfo, logWarning, notifyAllStatusChangeListeners, onAborted, onCompleted, onEnd, onFailed, removeStatusChangeListener, run, setErrorMessage, setErrorMessageArgs, setLastException, setWeight, validateInput, waitFor
-
-
-
-
Method Detail
-
initializeInternalVariables
protected void initializeInternalVariables() throws ThrowableBuilds all the tasks. Each task will be initialized before running it.- Overrides:
initializeInternalVariablesin classWorker- Throws:
Throwable
-
getProgressPercent
public int getProgressPercent()
- Specified by:
getProgressPercentin classWorker
-
execute
protected void execute() throws ThrowableRuns each contained task in order.
-
buildTasks
protected abstract void buildTasks() throws ThrowableCreates and adds tasks to this job.- Throws:
Throwable
-
hasTaskToRun
protected boolean hasTaskToRun()
-
nextTask
protected Worker nextTask()
-
addTask
protected <T extends Worker> T addTask(Class<T> type)
Creates and adds a task of the specified type.- Parameters:
type-- Returns:
-
addTask
protected <T extends Worker> void addTask(T task)
Throws IllegalStateException if invoked after run() is called- Parameters:
task-
-
addTasks
protected <C extends Collection<? extends Worker>> void addTasks(C tasks)
-
onTaskEnd
protected void onTaskEnd(Worker task)
Called when the task ends its execution. The status can beWorker.Status.COMPLETED,Worker.Status.FAILED,Worker.Status.ABORTED- Parameters:
task-
-
onTaskCompleted
protected void onTaskCompleted(Worker task)
Called when the task ends its execution with the statusWorker.Status.COMPLETED- Parameters:
task-
-
initializeTask
protected void initializeTask(Worker task)
Called before task execution.- Parameters:
task-
-
release
public void release()
Description copied from class:WorkerReleases the resource used during the execution
-
getCurrentTaskIndex
public int getCurrentTaskIndex()
-
getCurrentTask
public Worker getCurrentTask()
-
getJobManager
public JobManager getJobManager()
-
setJobManager
public void setJobManager(JobManager jobManager)
-
-