Class Job
java.lang.Object
com.inet.taskplanner.server.api.job.Job
A job is a unit of work that produces a result. A job generates
results that actions can process.
JobDefinition ----> JobFactory ----> Job
A job can have a condition, when the condition evaluates to false, then the result of the
job will not be processed. The condition is implementation-specific.
- Since:
- taskplanner 3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanevaluateCondition(@Nonnull ConditionDefinition conditionDefinition) Evaluate the condition represented by given definition for this job.final JobResultContainerexecute(@Nullable ProgressEventListener listener) Execute this Job.protected abstract JobResultContainerrun()This runs the job when theTaskExecutionis executed.protected voidsetProgress(int progress) Sets the progress of thisJoband propagates it to theProgressEventListener, if any.voidThis method is called by the task executor when it is requested to stop or cancel.
-
Constructor Details
-
Job
Creates a new Job instance.- Parameters:
condition- the condition set by the user, can be null!- Since:
- taskplanner 3.0
-
-
Method Details
-
execute
public final JobResultContainer execute(@Nullable ProgressEventListener listener) throws TaskExecutionException Execute this Job. Will run in the current Thread.- Parameters:
listener- the listener to notify in case any progress is made, may benullif the caller is not interested in progress events.- Returns:
- the
resultof this job - Throws:
TaskExecutionException- if an expected problem occurs- Since:
- taskplanner 3.0
-
run
This runs the job when theTaskExecutionis executed. This typically produces one or moreresults, but may also create no results in certain circumstances. Throwing exceptions will stop the task.- Returns:
- a result container, which can be empty or
null - Throws:
TaskExecutionException- if the task faced an unexpected error. Such an error will be visible in the task's execution history and it will break the task (no further jobs andresultActionswill be executed).- Since:
- taskplanner 3.0
-
evaluateCondition
Evaluate the condition represented by given definition for this job.When no condition was set for the job, then this method is not called.
- Parameters:
conditionDefinition- the condition configured by the client- Returns:
- true if the results must be processed, or in other words the condition is true, otherwise false.
- Since:
- taskplanner 3.0
-
setProgress
protected void setProgress(int progress) Sets the progress of thisJoband propagates it to theProgressEventListener, if any.- Parameters:
progress- the progress to be set. Will be bounded to [0..100]- Since:
- taskplanner 3.0
-
stopRequested
public void stopRequested()This method is called by the task executor when it is requested to stop or cancel. Implementations should stop therun()method within 30 seconds; otherwise the thread is regarded as dead and aThread.stop()might be invoked by the caller to ensure termination.
By default this method does nothing since it's assumed that most jobs will finish within 30 seconds either way.- Since:
- taskplanner 3.0
-