|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectit.sauronsoftware.cron4j.Task
public abstract class Task
Abstract base representation of a cron4j task.
Developers can extends this abstract class to build their own tasks.
Extending Task means, above all, implementing the
execute(TaskExecutionContext)
method. Within this method the
task must perform its operation. If the execute() method returns
regularly then the execution is considered to be successfully completed. If
execute() dies throwing a RuntimeException
then the task
execution is considered to be failed. The supplied parameter, which is a
TaskExecutionContext
instance, helps the developer in integrating his
task with the scheduler executor. Through the context the developer can check
if the execution has been paused or stopped, and he can also push back some
status informations by calling
TaskExecutionContext.setCompleteness(double)
and
TaskExecutionContext.setStatusMessage(String)
.
If the custom task supports pausing, stopping and/or tracking, that should be
notified by overriding canBePaused()
,
canBeStopped()
, supportsCompletenessTracking()
and/or supportsStatusTracking()
.
Constructor Summary | |
---|---|
Task()
Empty constructor, does nothing. |
Method Summary | |
---|---|
boolean |
canBePaused()
Checks whether this task supports pause requests. |
boolean |
canBeStopped()
Checks whether this task supports stop requests. |
abstract void |
execute(TaskExecutionContext context)
This method is called to require a task execution, and should contains the core routine of any scheduled task. |
boolean |
supportsCompletenessTracking()
Tests whether this task supports completeness tracking. |
boolean |
supportsStatusTracking()
Tests whether this task supports status tracking. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Task()
Method Detail |
---|
public boolean canBePaused()
Checks whether this task supports pause requests.
Default implementation returns false.
Task developers can override this method to let it return a true
value, and at the same time they have to implement the
execute(TaskExecutionContext)
method, so that pause requests
are really handled. This can be done calling regularly the
TaskExecutionContext.pauseIfRequested()
method during the task
execution.
public boolean canBeStopped()
Checks whether this task supports stop requests.
Default implementation returns false.
Task developers can override this method to let it return a true
value, and at the same time they have to implement the
execute(TaskExecutionContext)
method, so that stop requests
are really handled. This can be done checking regularly the
TaskExecutionContext.isStopped()
method during the task
execution.
public boolean supportsStatusTracking()
Tests whether this task supports status tracking.
Default implementation returns false.
The task developer can override this method and returns true,
having care to regularly calling the
TaskExecutionContext.setStatusMessage(String)
method during the
task execution.
public boolean supportsCompletenessTracking()
Tests whether this task supports completeness tracking.
Default implementation returns false.
The task developer can override this method and returns true,
having care to regularly calling the
TaskExecutionContext.setCompleteness(double)
method during the
task execution.
public abstract void execute(TaskExecutionContext context) throws java.lang.RuntimeException
This method is called to require a task execution, and should contains the core routine of any scheduled task.
If the execute() method ends regularly the scheduler will
consider the execution successfully completed, and this will be
communicated to any SchedulerListener
interested in it. If the
execute() method dies throwing a RuntimeException
the
scheduler will consider it as a failure notification. Any
SchedulerListener
will be notified about the occurred exception.
context
- The execution context.
java.lang.RuntimeException
- Task execution has somehow failed.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |