Class Executor

java.lang.Object
rife.scheduler.Executor
Direct Known Subclasses:
DbKeepAlive

public abstract class Executor extends Object
Executor is an abstract class that can be extended to implement the logic that happen when tasks of a particular type are executing through the scheduler.

By default, the task type will be determined by the name of the executor class, but it's possible to customize that by overriding the `getHandledTaskType()` method.

Since:
1.0
  • Field Details

    • DEFAULT_RESCHEDULE_DELAY

      public static final int DEFAULT_RESCHEDULE_DELAY
      See Also:
  • Constructor Details

    • Executor

      public Executor()
  • Method Details

    • executeTask

      public abstract boolean executeTask(Task task)
      Needs to be implemented with the logic that should happen when the scheduler executes a task.

      Sometimes tasks fail to be executed, or the right conditions can't be met. In that case, returning false from this method will make the scheduler reschedule the same task. The delay that is used for rescheduling is determined by this class's getRescheduleDelay() method.

      Parameters:
      task - the task that needs to be executed.
      Returns:
      true if the task successfully executed, or false if the task needs to be rescheduled
      Since:
      1.0
      See Also:
    • createTask

      public Task createTask()
      Create a new task instance with this executor's task type.
      Returns:
      a new task
      Since:
      1.0
    • getHandledTaskType

      public String getHandledTaskType()
      Returns a string identifying the type of tasks that this executor will handle.

      By default, this is the fully qualified class name of this executor, overriding this method allows for other type identifiers to be used.

      Returns:
      this executor's task type
      Since:
      1.0
    • getRescheduleDelay

      protected long getRescheduleDelay()
      Provides the delay in milliseconds that should be used when tasks are being rescheduled after non-successful execution.

      By default, this is 1000 ms (1 second), overriding this method allows for any other delay to be used.

      Returns:
      the delay in milliseconds for task rescheduling
      Since:
      1.0
    • getScheduler

      public Scheduler getScheduler()
      Retrieves the scheduler that this executor has been registered with.
      Returns:
      this executor's scheduler; or null if the executor has not been registered with a scheduler yet.
      Since:
      1.0