Class Job


  • public abstract class Job
    extends java.lang.Object
    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 Detail

      • Job

        public Job​(@Nullable
                   ConditionDefinition condition)
        Creates a new Job instance.
        Parameters:
        condition - the condition set by the user, can be null!
        Since:
        taskplanner 3.0
    • Method Detail

      • 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 be null 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

        protected abstract JobResultContainer run()
                                           throws TaskExecutionException
        This runs the job when the TaskExecution is executed. This typically produces one or more results, 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 and resultActions will be executed).
        Since:
        taskplanner 3.0
      • evaluateCondition

        protected abstract boolean evaluateCondition​(ConditionDefinition conditionDefinition)
        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 this Job and propagates it to the ProgressEventListener, 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 the run() method within 30 seconds, otherwise the thread will be regarded as 'dead' and a Thread.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