Package rife.scheduler
Class Scheduler
java.lang.Object
rife.scheduler.Scheduler
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionScheduler(TaskManager taskManager, TaskOptionManager taskOptionManager) Creates a new scheduler instance for the provided task manager and task option manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExecutor(Executor executor) Adds an executor to this scheduler.intConvenience method to add a task to the task manager that's registered with this scheduler.booleanaddTaskOption(TaskOption taskOption) Convenience method to add a task option to the task option manager that's registered with this scheduler.getExecutor(String taskType) Retrieves the executor that was registered for a particular task type.Retrieves the executors that have been registered with this scheduler.Retrieves this scheduler's task manager.Retrieves this scheduler's task option manager.booleanIndicates whether this scheduler is running or not.booleanremoveExecutor(Executor executor) Removes an executor from this scheduler.voidrun()voidsetSleepTime(int sleepTime) Set the time the schedule should sleep in between evaluating which tasks to execute.voidsetTaskManager(TaskManager taskManager) Sets the task manager of this scheduler.voidsetTaskOptionManager(TaskOptionManager taskOptionManager) Sets the task option manager of this scheduler.voidstart()Starts this scheduler.voidstop()Stops this scheduler.static voidStops all the active schedulers.
-
Field Details
-
DEFAULT_SLEEP_TIME
public static final int DEFAULT_SLEEP_TIME- See Also:
-
-
Constructor Details
-
Scheduler
Creates a new scheduler instance for the provided task manager and task option manager.- Parameters:
taskManager- the task manager to use for this schedulertaskOptionManager- the task option manager to use for this scheduler- Since:
- 1.0
-
-
Method Details
-
setTaskManager
Sets the task manager of this scheduler.- Parameters:
taskManager- the task manager to use- Since:
- 1.0
-
getTaskManager
Retrieves this scheduler's task manager.- Returns:
- this scheduler's task manager; or
nullif no task manager has been assigned yet - Since:
- 1.0
-
setTaskOptionManager
Sets the task option manager of this scheduler.- Parameters:
taskOptionManager- the task option manager to use- Since:
- 1.0
-
getTaskOptionManager
Retrieves this scheduler's task option manager.- Returns:
- this scheduler's task option manager; or
nullif no task option manager has been assigned yet - Since:
- 1.0
-
addTask
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
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:
trueif the task option was added successfully; orfalseotherwise- Since:
- 1.0
-
addExecutor
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
Removes an executor from this scheduler.- Parameters:
executor- the executor to remove- Returns:
trueif the scheduler was successfully remove; orfalseotherwise- Since:
- 1.0
-
getExecutor
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
nullif no executor is registered for that task type - Since:
- 1.0
-
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
500milliseconds.- 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:
trueif this scheduler is running; rofalseotherwise- Since:
- 1.0
-
stop
public void stop()Stops this scheduler.- Since:
- 1.0
-
run
public void run() -
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
-