org.oddjob.state
Class CascadeJob

java.lang.Object
  extended by org.oddjob.framework.BaseComponent
      extended by org.oddjob.framework.BasePrimary
          extended by org.oddjob.framework.StructuralJob<Object>
              extended by org.oddjob.state.CascadeJob
All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, ArooaSessionAware, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resetable, Stateful, Stoppable, Structural

public class CascadeJob
extends StructuralJob<Object>

Description

A job which triggers the next job after the previous one completes. This job differs from a SequentialJob task in that the latter follows the thread of execution, and only checks state to ensure it can continue. This job's thread of execution passes onwards after the cascade has been set up. This job will complete asynchronously once all it's children have completed.

State Operator

This job doesn't currently expose a State Operator property as SequentialJob does. The state behaviour is equivalent to the WORST state operator, which is what is desired in most situations. A stateOperator property may be added in future versions if needed.

Example

A cascade of two jobs.
<oddjob>
    <job>
        <state:cascade xmlns:state="http://rgordon.co.uk/oddjob/state">
            <jobs>
                <echo>This runs first.</echo>
                <echo>Then this.</echo>
            </jobs>
        </state:cascade>
    </job>
</oddjob>

Example

Showing cascade being used with ParallelJob. The cascade will wait for the parallel job to finish before running the third job.
<oddjob>
    <job>
        <state:cascade xmlns:state="http://rgordon.co.uk/oddjob/state">
            <jobs>
                <parallel>
                    <jobs>
                        <echo>Oranges could be first or second.</echo>
                        <echo>Pears could be first or second.</echo>
                    </jobs>
                </parallel>
                <echo>Apples are guaranteed to be third.</echo>
            </jobs>
        </state:cascade>
    </job>
</oddjob>
See Also:
Serialized Form
Author:
Rob Gordon

Field Summary
 
Fields inherited from class org.oddjob.framework.StructuralJob
childHelper, childStateReflector, stateHandler, stop, structuralState
 
Fields inherited from class org.oddjob.framework.BaseComponent
iconHelper
 
Constructor Summary
CascadeJob()
           
 
Method Summary
protected  void execute()
          Execute this job.
protected  StateOperator getInitialStateOp()
          Subclasses must provide the StateOperator that will decide how to evaluate the children's state.
protected  void onStop()
          Allow sub classes to do something on stop.
 void setExecutorService(ExecutorService executor)
           
 void setJobs(int index, Object child)
          Add a child job.
protected  void startChildStateReflector()
           
 
Methods inherited from class org.oddjob.framework.StructuralJob
addStructuralListener, fireDestroyedState, force, getStateChanger, hardReset, isStop, onDestroy, onReset, 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
 

Constructor Detail

CascadeJob

public CascadeJob()
Method Detail

setExecutorService

@Inject
public void setExecutorService(ExecutorService executor)

setJobs

public void setJobs(int index,
                    Object child)
Add a child job.

Property: jobs

Description: The child jobs.

Required: No, but pointless if missing.

Parameters:
child - A child

execute

protected void execute()
                throws InterruptedException
Description copied from class: StructuralJob
Execute this job.

Specified by:
execute in class StructuralJob<Object>
Throws:
InterruptedException

onStop

protected void onStop()
Description copied from class: StructuralJob
Allow sub classes to do something on stop.

Overrides:
onStop in class StructuralJob<Object>

getInitialStateOp

protected StateOperator getInitialStateOp()
Description copied from class: StructuralJob
Subclasses must provide the StateOperator that will decide how to evaluate the children's state.

Specified by:
getInitialStateOp in class StructuralJob<Object>
Returns:
A State Operator. Must not be null.

startChildStateReflector

protected void startChildStateReflector()
Overrides:
startChildStateReflector in class StructuralJob<Object>