|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.sauronsoftware.cron4j.Scheduler
public class Scheduler
The cron4j scheduler.
Constructor Summary | |
---|---|
Scheduler()
It builds and prepares a brand new Scheduler instance. |
Method Summary | |
---|---|
void |
addSchedulerListener(SchedulerListener listener)
Adds a SchedulerListener to the scheduler. |
void |
addTaskCollector(TaskCollector collector)
Adds a custom TaskCollector instance to the scheduler. |
void |
deschedule(java.lang.Object id)
Deprecated. Use deschedule(String) . |
void |
deschedule(java.lang.String id)
This methods cancels the scheduling of a task. |
void |
descheduleFile(java.io.File file)
Removes a File instance previously scheduled with the
scheduleFile(File) method. |
TaskExecutor[] |
getExecutingTasks()
Returns an array containing any currently executing task, in the form of TaskExecutor objects. |
java.lang.Object |
getGuid()
It returns the GUID for this scheduler. |
java.io.File[] |
getScheduledFiles()
Returns an array containing any File previously scheduled with
the scheduleFile(File) method. |
SchedulerListener[] |
getSchedulerListeners()
Returns an array containing any SchedulerListener previously
registered with the
addSchedulerListener(SchedulerListener) method. |
SchedulingPattern |
getSchedulingPattern(java.lang.String id)
This method retrieves a previously scheduled task scheduling pattern. |
Task |
getTask(java.lang.String id)
This method retrieves a previously scheduled task. |
TaskCollector[] |
getTaskCollectors()
Returns an array containing any custom TaskCollector instance
previously registered in the scheduler with the
addTaskCollector(TaskCollector) method. |
java.lang.Runnable |
getTaskRunnable(java.lang.Object id)
Deprecated. Use getTask(String) . |
java.lang.String |
getTaskSchedulingPattern(java.lang.Object id)
Deprecated. Use getSchedulingPattern(String) . |
java.util.TimeZone |
getTimeZone()
Returns the time zone applied by the scheduler. |
boolean |
isDaemon()
Tests whether this scheduler is a daemon scheduler. |
boolean |
isStarted()
Tests if this scheduler is started. |
TaskExecutor |
launch(Task task)
Executes immediately a task, without scheduling it. |
void |
removeSchedulerListener(SchedulerListener listener)
Removes a SchedulerListener previously registered with the
addSchedulerListener(SchedulerListener) method. |
void |
removeTaskCollector(TaskCollector collector)
Removes a previously registered custom TaskCollector instance. |
void |
reschedule(java.lang.Object id,
java.lang.String schedulingPattern)
Deprecated. Use reschedule(String, String) . |
void |
reschedule(java.lang.String id,
SchedulingPattern schedulingPattern)
This method changes the scheduling pattern of a task. |
void |
reschedule(java.lang.String id,
java.lang.String schedulingPattern)
This method changes the scheduling pattern of a task. |
java.lang.String |
schedule(SchedulingPattern schedulingPattern,
Task task)
This method schedules a task execution. |
java.lang.String |
schedule(java.lang.String schedulingPattern,
java.lang.Runnable task)
This method schedules a task execution. |
java.lang.String |
schedule(java.lang.String schedulingPattern,
Task task)
This method schedules a task execution. |
void |
scheduleFile(java.io.File file)
Adds a File instance to the scheduler. |
void |
setDaemon(boolean on)
Marks this scheduler daemon flag. |
void |
setTimeZone(java.util.TimeZone timezone)
Sets the time zone applied by the scheduler. |
void |
start()
This method starts the scheduler. |
void |
stop()
This method stops the scheduler execution. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Scheduler()
Method Detail |
---|
public java.lang.Object getGuid()
public void setTimeZone(java.util.TimeZone timezone)
Sets the time zone applied by the scheduler.
Current system time is adapted to the supplied time zone before comparing it with registered scheduling patterns. The result is that any supplied scheduling pattern is treated according to the specified time zone. In example, suppose:
The scheduler, before comparing system time with patterns, translates 10:00 from GMT+1 to GMT+3. It means that 10:00 becomes 12:00. The resulted time is then used by the scheduler to activate tasks. So, in the given configuration at the given moment, any task scheduled as 0 12 * * * will be executed, while any 0 10 * * * will not.
timezone
- The time zone applied by the scheduler.public java.util.TimeZone getTimeZone()
public boolean isDaemon()
public void setDaemon(boolean on) throws java.lang.IllegalStateException
on
- If true, the scheduler will spawn only daemon threads.
java.lang.IllegalStateException
- If the scheduler is started.public boolean isStarted()
public void scheduleFile(java.io.File file)
File
instance to the scheduler. Every minute the file will
be parsed. The scheduler will execute any declared task whose scheduling
pattern matches the current system time.
See CronParser
documentation for informations about the file
contents syntax.
file
- The File
instance.public void descheduleFile(java.io.File file)
File
instance previously scheduled with the
scheduleFile(File)
method.
file
- The File
instance.public java.io.File[] getScheduledFiles()
File
previously scheduled with
the scheduleFile(File)
method.
File
previously scheduled with
the scheduleFile(File)
method.public void addTaskCollector(TaskCollector collector)
TaskCollector
instance to the scheduler. The
supplied object, once added to the scheduler, will be query every minute
for its task list. The scheduler will execute any of the returned tasks
whose scheduling pattern matches the current system time.
collector
- The custom TaskCollector
instance.public void removeTaskCollector(TaskCollector collector)
TaskCollector
instance.
collector
- The custom TaskCollector
instance.public TaskCollector[] getTaskCollectors()
TaskCollector
instance
previously registered in the scheduler with the
addTaskCollector(TaskCollector)
method.
TaskCollector
instance
previously registered in the scheduler with the
addTaskCollector(TaskCollector)
method.public void addSchedulerListener(SchedulerListener listener)
SchedulerListener
to the scheduler. A
SchedulerListener
is notified every time a task is launching, has
succeeded or has failed.
listener
- The listener.public void removeSchedulerListener(SchedulerListener listener)
SchedulerListener
previously registered with the
addSchedulerListener(SchedulerListener)
method.
listener
- The listener.public SchedulerListener[] getSchedulerListeners()
SchedulerListener
previously
registered with the
addSchedulerListener(SchedulerListener)
method.
SchedulerListener
previously
registered with the
addSchedulerListener(SchedulerListener)
method.public TaskExecutor[] getExecutingTasks()
TaskExecutor
objects. Each running task is executed by a
different thread. A TaskExecutor
object allows the control of the
running task. The inner Task
representation could be retrieved,
the status of the task could be detected and the thread could be
interrupted using any standard Thread
method (
Thread.interrupt()
, etc
.
TaskExecutor
objects.public java.lang.String schedule(java.lang.String schedulingPattern, java.lang.Runnable task) throws InvalidPatternException
schedulingPattern
- The scheduling pattern for the task.task
- The task, as a plain Runnable object.
InvalidPatternException
- If the supplied pattern is not valid.public java.lang.String schedule(java.lang.String schedulingPattern, Task task) throws InvalidPatternException
schedulingPattern
- The scheduling pattern for the task.task
- The task, as a plain Runnable object.
InvalidPatternException
- If the supplied pattern is not valid.public java.lang.String schedule(SchedulingPattern schedulingPattern, Task task)
schedulingPattern
- The scheduling pattern for the task.task
- The task, as a plain Runnable object.
public void reschedule(java.lang.Object id, java.lang.String schedulingPattern) throws InvalidPatternException
reschedule(String, String)
.
id
- The ID assigned to the previously scheduled task.schedulingPattern
- The new scheduling pattern for the task.
InvalidPatternException
- If the supplied pattern is not valid.public void reschedule(java.lang.String id, java.lang.String schedulingPattern) throws InvalidPatternException
id
- The ID assigned to the previously scheduled task.schedulingPattern
- The new scheduling pattern for the task.
InvalidPatternException
- If the supplied pattern is not valid.public void reschedule(java.lang.String id, SchedulingPattern schedulingPattern)
id
- The ID assigned to the previously scheduled task.schedulingPattern
- The new scheduling pattern for the task.public void deschedule(java.lang.Object id)
deschedule(String)
.
id
- The ID of the task.public void deschedule(java.lang.String id)
id
- The ID of the task.public Task getTask(java.lang.String id)
id
- The task ID.
public SchedulingPattern getSchedulingPattern(java.lang.String id)
id
- The task ID.
public java.lang.Runnable getTaskRunnable(java.lang.Object id)
getTask(String)
.
id
- The task ID.
public java.lang.String getTaskSchedulingPattern(java.lang.Object id)
getSchedulingPattern(String)
.
id
- The task ID.
public TaskExecutor launch(Task task)
task
- The task.
TaskExecutor
executing the given task.
java.lang.IllegalStateException
- If the scheduler is not started.public void start() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- Thrown if this scheduler is already started.public void stop() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- Thrown if this scheduler is not started.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |