org.oddjob.state
Class EqualsState

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

public class EqualsState
extends StructuralJob<Stateful>
implements Stoppable

Description

Runs it's child job and then compares the state of the child job to the given state. It's own state is complete if the states match, incomplete otherwise.

This job is probably most useful in it's 'not equals' form - i.e. to check when something hasn't completed.

Example

COMPLETE when the child job isn't complete. This example demonstrates how the state:equals job can be used to reverse the meaning of the exists job. A request to shutdown a database may complete asynchronously, and the only way to tell if shutdown is complete is to check that the Database's lock file has be removed. This example demonstrates how Oddjob can check for this situation before attempting to back up the database.
<oddjob id="this">
    <job>
        <scheduling:retry name="Database Backup" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">
            <schedule>
                <schedules:interval interval="00:00:02" xmlns:schedules="http://rgordon.co.uk/oddjob/schedules"/>
            </schedule>
            <job>
                <sequential id="db-backup">
                    <jobs>
                        <state:equals state="!COMPLETE" xmlns:state="http://rgordon.co.uk/oddjob/state">
                            <job>
                                <state:resets harden="true">
                                    <job>
                                        <exists file="${db.lock.file}"/>
                                    </job>
                                </state:resets>
                            </job>
                        </state:equals>
                        <echo>Backing up the Database...</echo>
                    </jobs>
                </sequential>
            </job>
        </scheduling:retry>
    </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
EqualsState()
           
 
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.
 StateCondition getState()
           
 void setJob(Stateful job)
           
 void setState(StateCondition state)
           
 
Methods inherited from class org.oddjob.framework.StructuralJob
addStructuralListener, fireDestroyedState, force, getStateChanger, hardReset, isStop, onDestroy, onReset, onStop, removeStructuralListener, run, softReset, startChildStateReflector, 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.Stoppable
stop
 
Methods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
 

Constructor Detail

EqualsState

public EqualsState()
Method Detail

getState

public StateCondition getState()

setState

public void setState(StateCondition state)

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<Stateful>
Returns:
A State Operator. Must not be null.

setJob

public void setJob(Stateful job)

Property: job

Description: The job to run who's state will be compared.

Required: Yes.


execute

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

Specified by:
execute in class StructuralJob<Stateful>
Throws:
Exception - If the unexpected occurs.
Throwable