org.oddjob.framework
Class StructuralJob<E>

java.lang.Object
  extended by org.oddjob.framework.BaseComponent
      extended by org.oddjob.framework.BasePrimary
          extended by org.oddjob.framework.StructuralJob<E>
All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, ArooaSessionAware, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resetable, Stateful, Stoppable, Structural
Direct Known Subclasses:
CascadeJob, EqualsState, ForEachJob, IfJob, JoinJob, MegaBeanBus, MultiExplorerLauncher, Oddjob, RepeatJob, Resets, RunJob, SequentialJob, SimultaneousStructural

public abstract class StructuralJob<E>
extends BasePrimary
implements Runnable, Serializable, Stoppable, Resetable, Stateful, Forceable, Structural

An abstract implementation of a job which provides common functionality to concrete sub classes.

See Also:
Serialized Form
Author:
Rob Gordon

Field Summary
protected  ChildHelper<E> childHelper
          Track changes to children an notify listeners.
protected  StateExchange childStateReflector
          Reflect state of children.
protected  ParentStateHandler stateHandler
           
protected  boolean stop
           
protected  StructuralStateHelper structuralState
          Calculate our state based on children.
 
Fields inherited from class org.oddjob.framework.BaseComponent
iconHelper
 
Constructor Summary
StructuralJob()
          Constructor.
 
Method Summary
 void addStructuralListener(StructuralListener listener)
          Add a listener.
protected abstract  void execute()
          Execute this job.
protected  void fireDestroyedState()
          Internal method to fire state.
 void force()
          Force the job to COMPLETE.
protected abstract  StateOperator getInitialStateOp()
          Subclasses must provide the StateOperator that will decide how to evaluate the children's state.
protected  StateChanger<ParentState> getStateChanger()
           
 boolean hardReset()
          Perform a hard reset on the job.
 boolean isStop()
          Expose the internal stop flag as a read only property.
protected  void onDestroy()
          Subclasses override this method to clear up resources.
protected  void onReset()
          Allow sub classes to do something on reset.
protected  void onStop()
          Allow sub classes to do something on stop.
 void removeStructuralListener(StructuralListener listener)
          Remove a listener.
 void run()
          Implement the main execute method for a job.
 boolean softReset()
          Perform a soft reset on the job.
protected  void startChildStateReflector()
           
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

childHelper

protected transient ChildHelper<E> childHelper
Track changes to children an notify listeners.


structuralState

protected transient StructuralStateHelper structuralState
Calculate our state based on children.


childStateReflector

protected transient StateExchange childStateReflector
Reflect state of children.


stop

protected transient volatile boolean stop

Property:

Description: Read only view of the internal stop flag. This flag is cleared with a reset.

Required: Read only.

Constructor Detail

StructuralJob

public StructuralJob()
Constructor.

Method Detail

stateHandler

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

getStateChanger

protected final StateChanger<ParentState> getStateChanger()

getInitialStateOp

protected abstract StateOperator getInitialStateOp()
Subclasses must provide the StateOperator that will decide how to evaluate the children's state.

Returns:
A State Operator. Must not be null.

execute

protected abstract void execute()
                         throws Throwable
Execute this job.

Throws:
Exception - If the unexpected occurs.
Throwable

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

startChildStateReflector

protected void startChildStateReflector()

stop

public void stop()
          throws FailedToStopException
Implementation for a typical stop.

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()
               throws FailedToStopException
Allow sub classes to do something on stop.

Throws:
FailedToStopException

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()
Allow sub classes to do something on reset.


force

public void force()
Force the job to COMPLETE.

Specified by:
force in interface Forceable

addStructuralListener

public void addStructuralListener(StructuralListener listener)
Add a listener. The listener will immediately receive 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 listener.

isStop

public boolean isStop()
Expose the internal stop flag as a read only property.

Returns:
the stop flag.

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