org.oddjob.scheduling
Class TimerBase

java.lang.Object
  extended by org.oddjob.framework.BaseComponent
      extended by org.oddjob.framework.BasePrimary
          extended by org.oddjob.scheduling.ScheduleBase
              extended by org.oddjob.scheduling.TimerBase
All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, PropertyChangeNotifier, Iconic, LogEnabled, Resetable, Stateful, Stoppable, Structural
Direct Known Subclasses:
Retry, Timer

public abstract class TimerBase
extends ScheduleBase

Common functionality for Timers.

See Also:
Serialized Form
Author:
rob

Field Summary
protected  Map<Object,Object> contextData
          Provided to the schedule.
 
Fields inherited from class org.oddjob.scheduling.ScheduleBase
childHelper, childStateReflector, stateHandler, stop, structuralState
 
Fields inherited from class org.oddjob.framework.BaseComponent
iconHelper
 
Constructor Summary
TimerBase()
           
 
Method Summary
protected  void begin()
          Sub classes must override this to submit the first execution.
 Clock getClock()
          Get the current clock.
 ScheduleResult getCurrent()
          Get the current/next interval.
 Date getLastDue()
          Get the last due date.
protected abstract  Interval getLimits()
           
 Date getNextDue()
          Get the next due date.
 Schedule getSchedule()
           
 String getTimeZone()
          Get the time zone id to use in this schedule.
protected  void onReset()
           
protected  void onStop()
           
protected  void postStop()
           
protected abstract  void rescheduleOn(State state)
           
protected abstract  void reset(Resetable job)
           
protected  void scheduleFrom(Date date)
           
 void setClock(Clock clock)
          Set the clock.
 void setJob(Runnable job)
           
protected  void setNextDue(Date nextDue)
          Set the next due date.
 void setReschedule(Date reSchedule)
           
 void setSchedule(Schedule schedule)
          Set the schedule.
 void setScheduleExecutorService(ScheduledExecutorService scheduler)
           
 void setTimeZone(String timeZoneId)
          Set the time zone.
 
Methods inherited from class org.oddjob.scheduling.ScheduleBase
addStructuralListener, fireDestroyedState, getStateChanger, getStateOp, hardReset, onDestroy, removeStructuralListener, run, softReset, stateHandler, stop
 
Methods inherited from class org.oddjob.framework.BasePrimary
configure, getName, logger, logger, loggerName, save, setName, toString
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
 

Field Detail

contextData

protected final Map<Object,Object> contextData
Provided to the schedule.

Constructor Detail

TimerBase

public TimerBase()
Method Detail

setScheduleExecutorService

@Inject
public void setScheduleExecutorService(ScheduledExecutorService scheduler)

begin

protected void begin()
              throws ComponentPersistException
Description copied from class: ScheduleBase
Sub classes must override this to submit the first execution.

Specified by:
begin in class ScheduleBase
Throws:
ComponentPersistException

onStop

protected void onStop()
Overrides:
onStop in class ScheduleBase

postStop

protected void postStop()
Overrides:
postStop in class ScheduleBase

onReset

protected void onReset()
Overrides:
onReset in class ScheduleBase

getTimeZone

public String getTimeZone()
Get the time zone id to use in this schedule.

Returns:
The time zone id being used.

setTimeZone

public void setTimeZone(String timeZoneId)
Set the time zone.

Parameters:
timeZoneId - the timeZoneId.

setSchedule

public void setSchedule(Schedule schedule)
Set the schedule.

Parameters:
schedule - The schedule.

getSchedule

public Schedule getSchedule()

setReschedule

public void setReschedule(Date reSchedule)
                   throws ComponentPersistException

Property: reschedule

Description: Reschedule from the given date/time.

Required: Only available when running.

Throws:
ComponentPersistException

scheduleFrom

protected void scheduleFrom(Date date)
                     throws ComponentPersistException
Throws:
ComponentPersistException

getClock

public Clock getClock()
Get the current clock.

Returns:
The clock

setClock

public void setClock(Clock clock)
Set the clock. Only useful for testing.

Parameters:
clock - The clock.

getNextDue

public Date getNextDue()
Get the next due date.

Returns:
The next due date

setNextDue

protected void setNextDue(Date nextDue)
                   throws ComponentPersistException
Set the next due date.

Parameters:
nextDue - The date schedule is next due.
Throws:
ComponentPersistException

getCurrent

public ScheduleResult getCurrent()
Get the current/next interval.

Returns:
The interval, null if not due again.

getLastDue

public Date getLastDue()
Get the last due date.

Returns:
The last due date, null when a timer starts for the first time.

setJob

public void setJob(Runnable job)

Property: job

Description: The job to run when it's due.

Required: Yes.


getLimits

protected abstract Interval getLimits()

rescheduleOn

protected abstract void rescheduleOn(State state)
                              throws ComponentPersistException
Throws:
ComponentPersistException

reset

protected abstract void reset(Resetable job)