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
-
Constructor Summary
ConstructorDescriptionScheduler
(TaskManager taskManager, TaskOptionManager taskOptionManager) Creates a new scheduler instance for the provided task manager and task option manager. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExecutor
(Executor executor) Adds an executor to this scheduler.int
Convenience method to add a task to the task manager that's registered with this scheduler.boolean
addTaskOption
(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.boolean
Indicates whether this scheduler is running or not.boolean
removeExecutor
(Executor executor) Removes an executor from this scheduler.void
run()
void
setSleepTime
(int sleepTime) Set the time the schedule should sleep in between evaluating which tasks to execute.void
setTaskManager
(TaskManager taskManager) Sets the task manager of this scheduler.void
setTaskOptionManager
(TaskOptionManager taskOptionManager) Sets the task option manager of this scheduler.void
start()
Starts this scheduler.void
stop()
Stops this scheduler.static void
Stops 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
null
if 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
null
if 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:
true
if the task option was added successfully; orfalse
otherwise- 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:
true
if the scheduler was successfully remove; orfalse
otherwise- 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
null
if 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
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; rofalse
otherwise- 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
-