org.oddjob.scheduling
Class Trigger
java.lang.Object
org.oddjob.framework.BaseComponent
org.oddjob.framework.BasePrimary
org.oddjob.scheduling.ScheduleBase
org.oddjob.scheduling.Trigger
- All Implemented Interfaces:
- Serializable, Runnable, ArooaContextAware, ArooaSessionAware, PropertyChangeNotifier, Iconic, LogEnabled, Resetable, Stateful, Stoppable, Structural
public class Trigger
- extends ScheduleBase
Description
A trigger runs it's job when the job being triggered
on enters the state specified.
Once the trigger's job runs the trigger
will reflect the state of the it's job. The trigger will continue to
reflect it's job's state until it is reset.
Subsequent state changes in
the triggering job are ignored until the trigger is reset and re-run.
If the triggering job is destroyed, because it is deleted or on a remote
server the trigger will enter an exception state.
Example
A simple trigger.
<oddjob id="this">
<job>
<sequential name="Trigger Example">
<jobs>
<scheduling:trigger name="Alert Trigger" on="${important}" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">
<job>
<echo name="Alert">Important job has completed!</echo>
</job>
</scheduling:trigger>
<folder name="A Folder of Jobs">
<jobs>
<echo id="important" name="Run Me">I'm important</echo>
</jobs>
</folder>
</jobs>
</sequential>
</job>
</oddjob>
Example
A trigger that runs once two other jobs have completed.
<oddjob xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling" xmlns:state="http://rgordon.co.uk/oddjob/state">
<job>
<sequential name="Trigger on Two Things">
<jobs>
<scheduling:trigger id="trigger" on="${watch-both}">
<job>
<echo id="notify" name="Triggered Job">You ran two things!</echo>
</job>
</scheduling:trigger>
<state:and id="watch-both" name="Watch Two Jobs">
<jobs>
<state:mirror job="${thing1}" name="Mirror Job 1"/>
<state:mirror job="${thing2}" name="Mirror Job 2"/>
</jobs>
</state:and>
<folder name="A Folder of Jobs">
<jobs>
<echo id="thing1" name="Run me!">Thank you</echo>
<echo id="thing2" name="Run me!">Thank you</echo>
</jobs>
</folder>
</jobs>
</sequential>
</job>
</oddjob>
Example
Cancelling a trigger.
<oddjob id="this" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">
<job>
<sequential name="Trigger Example">
<jobs>
<scheduling:trigger id="trigger" name="Alert Trigger" on="${our-job}" state="FAILURE" cancelWhen="FINISHED">
<job>
<echo name="Alert" id="triggered-job">That job shouldn't fail!</echo>
</job>
</scheduling:trigger>
<folder name="A Folder of Jobs">
<jobs>
<echo id="our-job" name="Run Me">I won't fail</echo>
</jobs>
</folder>
</jobs>
</sequential>
</job>
</oddjob>
Example
Examples Elsewhere.
- The scheduling example (
examples/scheduling/dailyftp.xml
)
uses a trigger to send an email if one of the FTP transfers fails.
- See Also:
- Serialized Form
- Author:
- Rob Gordon.
Methods inherited from class org.oddjob.scheduling.ScheduleBase |
addStructuralListener, fireDestroyedState, getStateChanger, hardReset, onDestroy, onReset, removeStructuralListener, run, setStateStartingAndIconSleeping, softReset, stateHandler, stop |
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 |
Trigger
public Trigger()
setExecutorService
@Inject
public void setExecutorService(ExecutorService executor)
getStateOp
protected StateOperator getStateOp()
- Description copied from class:
ScheduleBase
- Sub classes provide the state operator that is used to calculate the subclasses
completion state.
- Specified by:
getStateOp
in class ScheduleBase
- Returns:
- The operator. Must not be null.
begin
protected void begin()
- Description copied from class:
ScheduleBase
- Sub classes must override this to submit the first execution.
- Specified by:
begin
in class ScheduleBase
onStop
protected void onStop()
- Overrides:
onStop
in class ScheduleBase
postStop
protected void postStop()
- Overrides:
postStop
in class ScheduleBase
setJob
public void setJob(Runnable job)
Property: job
Description: The job to run when the trigger fires.
Required: Yes.
getState
public StateCondition getState()
setState
public void setState(StateCondition state)
getCancelWhen
public StateCondition getCancelWhen()
setCancelWhen
public void setCancelWhen(StateCondition cancelWhen)
isNewOnly
public boolean isNewOnly()
setNewOnly
public void setNewOnly(boolean newEventOnly)
getOn
public Stateful getOn()
setOn
public void setOn(Stateful triggerOn)