Class Job
java.lang.Object
com.inet.taskplanner.server.api.job.Job
A Job is a bunch of work which produces a result. A Job generates
results
which 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 Job implementation specific.
- Since:
- taskplanner 3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
evaluateCondition
(ConditionDefinition conditionDefinition) Evaluate the condition represented by given definition for this job.final JobResultContainer
execute
(@Nullable ProgressEventListener listener) Execute this Job.protected abstract JobResultContainer
run()
This runs the job when theTaskExecution
is executed.protected void
setProgress
(int progress) Sets the progress of thisJob
and propagates it to theProgressEventListener
, if any.void
This method is called by the task executor in case the executor was requested to stop/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 @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 benull
if the caller is not interested in progress events.- Returns:
- the
result
of this job - Throws:
TaskExecutionException
- throws when an 'expected' problem occurs.- Since:
- taskplanner 3.0
-
run
This runs the job when theTaskExecution
is executed. This typically produces one or moreresults
, but may also create no results in certain circumstances. Throwing exceptions will stop the task.- Returns:
- a list of results, can be empty. Null is also allowed.
- 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 andresultActions
will 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 thisJob
and 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 in case the executor was requested to stop/cancel. It's supposed to stop therun()
method within 30 seconds, otherwise the thread will be regarded as 'dead' and aThread.stop()
might be invoked by the caller to ensure a 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
-