org.oddjob.scheduling
Class Timer
java.lang.Object
org.oddjob.framework.BaseComponent
org.oddjob.framework.BasePrimary
org.oddjob.scheduling.ScheduleBase
org.oddjob.scheduling.TimerBase
org.oddjob.scheduling.Timer
- All Implemented Interfaces:
- Serializable, Runnable, ArooaContextAware, PropertyChangeNotifier, Iconic, LogEnabled, Resetable, Stateful, Stoppable, Structural
public class Timer
- extends TimerBase
Description
Provides a simple timer for periodic or once only
execution of the child job.
Schedules
Once only execution:
Recurring executions:
Holidays:
Missed Executions
If Oddjob is running with a persister missed executions fire immediately one
after the other until all missed executions have run.
This can be overridden with the skipMissedRuns property.
If a timer is started after the initial execution time but within the interval
of the schedule - execution will happen immediately. Extended intervals are created
using the from properties instead of the at/in/on properties
of schedules.
Retrying Failed Jobs
Nest a Retry job.
Recording the Outcome of Runs
Nest an ArchiveJob.
Distributed Scheduling
Nest a GrabJob.
For More Information
For more information see the Scheduling section of the User Guide.Example
A Timer that runs at 10am each day, Monday to Friday.
<oddjob>
<job>
<scheduling:timer id="timer" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
<schedule>
<schedules:weekly from="Monday" to="Friday">
<refinement>
<schedules:daily at="10:00"/>
</refinement>
</schedules:weekly>
</schedule>
<job>
<echo id="work">Doing some work at ${timer.current.fromDate}</echo>
</job>
</scheduling:timer>
</job>
</oddjob>
Example
Run once at 10am or any time after.
<oddjob>
<job>
<sequential>
<jobs>
<echo id="big-report" name="Pretend this is a Long Running Report">Meaning of Life: 42</echo>
<scheduling:timer id="timer" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">
<schedule>
<schedules:time from="10:00" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
</schedule>
<job>
<echo name="Pretend this Forwards the Long Running Report">Emailing: ${big-report.text}</echo>
</job>
</scheduling:timer>
</jobs>
</sequential>
</job>
</oddjob>
If the report completes before 10am the timer will schedule it to be e-mailed
at 10am. If the report completes after 10am it is e-mailed immediately.Example
Use a timer to stop a long running job.
<oddjob>
<job>
<sequential id="main" name="Stop Overdue Job">
<jobs>
<scheduling:timer xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">
<schedule>
<schedules:count count="1" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules">
<refinement>
<schedules:after>
<schedule>
<schedules:interval interval="00:00:10"/>
</schedule>
</schedules:after>
</refinement>
</schedules:count>
</schedule>
<job>
<stop job="${long-job}" name="Stop Long Running Job"/>
</job>
</scheduling:timer>
<wait id="long-job" name="A Long Running Job"/>
</jobs>
</sequential>
</job>
</oddjob>
The job will be stopped after 10 seconds. If the job has already completed
the stop will have no affect.- See Also:
- Serialized Form
- Author:
- Rob Gordon.
|
Constructor Summary |
Timer()
|
| Methods inherited from class org.oddjob.scheduling.TimerBase |
getClock, getCurrent, getLastDue, getNextDue, getSchedule, getTimeZone, onReset, onStop, postStop, scheduleFrom, setClock, setJob, setNextDue, setReschedule, setSchedule, setScheduleExecutorService, setTimeZone |
| Methods inherited from class org.oddjob.framework.BaseComponent |
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSession |
Timer
public Timer()
getStateOp
protected StateOperator getStateOp()
- Description copied from class:
ScheduleBase
- Sub classes provide the state operator that is used to calculate the subclasses
completion state.
- Specified by:
getStateOp in class ScheduleBase
- Returns:
- The operator. Must not be null.
begin
protected void begin()
throws ComponentPersistException
- Description copied from class:
ScheduleBase
- Sub classes must override this to submit the first execution.
- Overrides:
begin in class TimerBase
- Throws:
ComponentPersistException
setHaltOnFailure
public void setHaltOnFailure(boolean haltOnFailure)
isHaltOnFailure
public boolean isHaltOnFailure()
isSkipMissedRuns
public boolean isSkipMissedRuns()
setSkipMissedRuns
public void setSkipMissedRuns(boolean skipMissedRuns)
getLimits
protected IntervalTo getLimits()
- Specified by:
getLimits in class TimerBase
rescheduleOn
protected void rescheduleOn(State state)
throws ComponentPersistException
- Specified by:
rescheduleOn in class TimerBase
- Throws:
ComponentPersistException
reset
protected void reset(Resetable job)
- Specified by:
reset in class TimerBase