Class Scheduler

java.lang.Object
rife.scheduler.Scheduler
All Implemented Interfaces:
Runnable

public class Scheduler extends Object implements Runnable
The Scheduler class performs the actual task scheduling and dispatch to the appropriate executors.

You would typically not create an instance of Scheduler yourself, but instead obtain the one that is provided by MemoryScheduling or DatabaseScheduling

Since:
1.0
  • Field Details

  • Constructor Details

    • Scheduler

      public Scheduler(TaskManager taskManager, TaskOptionManager taskOptionManager)
      Creates a new scheduler instance for the provided task manager and task option manager.
      Parameters:
      taskManager - the task manager to use for this scheduler
      taskOptionManager - the task option manager to use for this scheduler
      Since:
      1.0
  • Method Details

    • setTaskManager

      public void setTaskManager(TaskManager taskManager)
      Sets the task manager of this scheduler.
      Parameters:
      taskManager - the task manager to use
      Since:
      1.0
    • getTaskManager

      public TaskManager getTaskManager()
      Retrieves this scheduler's task manager.
      Returns:
      this scheduler's task manager; or null if no task manager has been assigned yet
      Since:
      1.0
    • setTaskOptionManager

      public void setTaskOptionManager(TaskOptionManager taskOptionManager)
      Sets the task option manager of this scheduler.
      Parameters:
      taskOptionManager - the task option manager to use
      Since:
      1.0
    • getTaskOptionManager

      public TaskOptionManager getTaskOptionManager()
      Retrieves this scheduler's task option manager.
      Returns:
      this scheduler's task option manager; or null if no task option manager has been assigned yet
      Since:
      1.0
    • addTask

      public int addTask(Task task)
      Convenience method to add a task to the task manager that's registered with this scheduler.
      Parameters:
      task - the task instance to add
      Returns:
      the unique ID of the task
      Since:
      1.0
    • addTaskOption

      public boolean addTaskOption(TaskOption taskOption)
      Convenience method to add a task option to the task option manager that's registered with this scheduler.
      Parameters:
      taskOption - the task option instance to add
      Returns:
      true if the task option was added successfully; or false otherwise
      Since:
      1.0
    • addExecutor

      public void addExecutor(Executor executor) throws SchedulerException
      Adds an executor to this scheduler.
      Parameters:
      executor - the executor to add to this scheduler
      Throws:
      SchedulerException - when this executor is already registered with another scheduler; or when another executor is already registered for this task type
      Since:
      1.0
    • removeExecutor

      public boolean removeExecutor(Executor executor)
      Removes an executor from this scheduler.
      Parameters:
      executor - the executor to remove
      Returns:
      true if the scheduler was successfully remove; or false otherwise
      Since:
      1.0
    • getExecutor

      public Executor getExecutor(String taskType)
      Retrieves the executor that was registered for a particular task type.
      Parameters:
      taskType - the task type to find the executor for
      Returns:
      the executor handling the provided task type; or null if no executor is registered for that task type
      Since:
      1.0
    • getExecutors

      public Collection<Executor> getExecutors()
      Retrieves the executors that have been registered with this scheduler.
      Returns:
      the collection of this scheduler's executors
      Since:
      1.0
    • setSleepTime

      public void setSleepTime(int sleepTime)
      Set the time the schedule should sleep in between evaluating which tasks to execute.

      This defaults to 500 milliseconds.

      Parameters:
      sleepTime - the time to sleep between task evaluations in milliseconds
      Since:
      1.0
    • start

      public void start()
      Starts this scheduler.
      Since:
      1.0
    • isRunning

      public boolean isRunning()
      Indicates whether this scheduler is running or not.
      Returns:
      true if this scheduler is running; ro false otherwise
      Since:
      1.0
    • stop

      public void stop()
      Stops this scheduler.
      Since:
      1.0
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • stopAllActiveSchedulers

      public static void stopAllActiveSchedulers()
      Stops all the active schedulers.

      This can be used to ensure that no schedulers keeps running when an application shuts down. It's already used by the destroy method of the RifeFilter.

      Since:
      1.6.1