org.oddjob.scheduling
Class ScheduleBase

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

public abstract class ScheduleBase
extends BasePrimary
implements Runnable, Stoppable, Serializable, Resetable, Stateful, Structural

Common functionality for jobs that schedule things.

See Also:
Serialized Form
Author:
Rob Gordon

Field Summary
protected  CountDownLatch begun
           
protected  ChildHelper<Runnable> childHelper
          Track the child.
protected  StateExchange childStateReflector
           
protected  ParentStateHandler stateHandler
          Fires state events.
protected  boolean stop
          Stop flag.
protected  StructuralStateHelper structuralState
           
 
Fields inherited from class org.oddjob.framework.BaseComponent
iconHelper
 
Constructor Summary
ScheduleBase()
          Default Constructor.
 
Method Summary
 void addStructuralListener(StructuralListener listener)
          Add a listener.
protected abstract  void begin()
          Sub classes must override this to submit the first execution.
protected  void fireDestroyedState()
          Internal method to fire state.
protected  StateChanger<ParentState> getStateChanger()
           
protected abstract  StateOperator getStateOp()
          Sub classes provide the state operator that is used to calculate the subclasses completion state.
 boolean hardReset()
          Perform a hard reset on the job.
protected  void onDestroy()
          Subclasses override this method to clear up resources.
protected  void onReset()
           
protected  void onStop()
           
protected  void postStop()
           
 void removeStructuralListener(StructuralListener listener)
          Remove a listener.
 void run()
          Implement the main execute method for a job.
protected  void setStateStartingAndIconSleeping()
          Utility method to set the state to STARTED but the icon to SLEEPING.
 boolean softReset()
          Perform a soft reset on the job.
protected  ParentStateHandler stateHandler()
           
 void stop()
          Implementation for a typical 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

stateHandler

protected transient ParentStateHandler stateHandler
Fires state events.


childHelper

protected transient ChildHelper<Runnable> childHelper
Track the child.


structuralState

protected transient StructuralStateHelper structuralState

childStateReflector

protected transient StateExchange childStateReflector

stop

protected transient volatile boolean stop
Stop flag.


begun

protected transient CountDownLatch begun
Constructor Detail

ScheduleBase

public ScheduleBase()
Default Constructor.

Method Detail

stateHandler

protected ParentStateHandler stateHandler()
Specified by:
stateHandler in class BaseComponent

getStateChanger

protected StateChanger<ParentState> getStateChanger()

getStateOp

protected abstract StateOperator getStateOp()
Sub classes provide the state operator that is used to calculate the subclasses completion state.

Returns:
The operator. Must not be null.

begin

protected abstract void begin()
                       throws ComponentPersistException
Sub classes must override this to submit the first execution.

Throws:
ComponentPerisistException - If the scheduled time can't be saved.
ComponentPersistException

run

public final void run()
Implement the main execute method for a job. This surrounds the doExecute method of the sub class and sets state for the job.

Specified by:
run in interface Runnable

setStateStartingAndIconSleeping

protected final void setStateStartingAndIconSleeping()
Utility method to set the state to STARTED but the icon to SLEEPING.


stop

public final void stop()
                throws FailedToStopException
Implementation for a typical stop. Subclasses must implement Stoppable to take advantage of it.

This stop implementation doesn't check that the job is executing as stop messages must cascade down the hierarchy to manually started jobs.

Specified by:
stop in interface Stoppable
Throws:
FailedToStopException

onStop

protected void onStop()

postStop

protected void postStop()

softReset

public boolean softReset()
Perform a soft reset on the job.

Specified by:
softReset in interface Resetable
Returns:
true if successful.

hardReset

public boolean hardReset()
Perform a hard reset on the job.

Specified by:
hardReset in interface Resetable
Returns:
true if successful.

onReset

protected void onReset()

addStructuralListener

public void addStructuralListener(StructuralListener listener)
Add a listener. The listener will immediately recieve add notifications for all existing children.

Specified by:
addStructuralListener in interface Structural
Parameters:
listener - The listener.

removeStructuralListener

public void removeStructuralListener(StructuralListener listener)
Remove a listener.

Specified by:
removeStructuralListener in interface Structural
Parameters:
listener - The listner.

onDestroy

protected void onDestroy()
Description copied from class: BaseComponent
Subclasses override this method to clear up resources.

Overrides:
onDestroy in class BaseComponent

fireDestroyedState

protected void fireDestroyedState()
Internal method to fire state.

Specified by:
fireDestroyedState in class BaseComponent