Package org.oddjob.events
Class Trigger<T>
- All Implemented Interfaces:
Serializable,Runnable,Consumer<T>,ArooaContextAware,ArooaSessionAware,Outbound<T>,Forceable,PropertyChangeNotifier,Iconic,LogEnabled,Resettable,Stateful,Stoppable,Structural
- Author:
- Rob Gordon.
- See Also:
Description
Trigger on an event. This is a work in progress replacement forTrigger. The intention being that it has the ability
to fire off any event, not just a state change.
The job has two children; the first being the source of the event that causes the trigger, and the second is the job that is run as the result of the trigger firing.
Example
A trigger expression based on the state of some jobs.
<oddjob>
<job>
<sequential name="Trigger on Two Things">
<jobs>
<bean class="org.oddjob.events.Trigger" id="trigger">
<jobs>
<bean class="org.oddjob.state.expr.StateExpressionType">
thing1 is success and thing2 is success and not (thing3 is success or thing4 is success)
</bean>
<echo id="notify" name="Triggered Job">You ran two things!</echo>
</jobs>
</bean>
<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>
<echo id="thing3" name="Don't Run me!">Uh oh!</echo>
<echo id="thing4" name="Don't Run me!">Uh oh!</echo>
</jobs>
</folder>
</jobs>
</sequential>
</job>
</oddjob>
A trigger as a destination in Bean Bus. The queue is required to keep the bus open while the triggered
job completes. Using just a bus driver would cause the bus to be closed when the driver completes and this
might not give time for the triggered job to complete because it happens asynchronously. The solution is to
make Trigger flushable and not let flush complete until the triggered job completes.
<oddjob>
<job>
<parallel>
<jobs>
<bus:queue id="queue" xmlns:bus="oddjob:beanbus"/>
<bus:bus xmlns:bus="oddjob:beanbus">
<of>
<bus:driver>
<values>
<value value="${queue}"/>
</values>
</bus:driver>
<bus:filter id="filter">
<predicate>
<bean class="org.oddjob.events.TriggerTest$OnlyApple"/>
</predicate>
</bus:filter>
<events:trigger beDestination="true" id="trigger" xmlns:events="oddjob:events">
<jobs>
<sequential>
<jobs>
<echo id="result">
Result: ${trigger.trigger}
</echo>
<stop job="${queue}" name="Stop Queue"/>
</jobs>
</sequential>
</jobs>
</events:trigger>
</of>
</bus:bus>
<folder>
<jobs>
<set id="put1" name="Put Banana">
<values>
<value key="queue.put" value="banana"/>
</values>
</set>
<set id="put2" name="Put Apple">
<values>
<value key="queue.put" value="Apple"/>
</values>
</set>
</jobs>
</folder>
</jobs>
</parallel>
</job>
</oddjob>
Trigger with the first result of a Bean Bus pipeline.
<oddjob>
<job>
<events:trigger id="trigger" xmlns:events="oddjob:events">
<jobs>
<bus:driver xmlns:bus="oddjob:beanbus">
<values>
<list>
<values>
<value value="foo"/>
</values>
</list>
</values>
</bus:driver>
<echo id="echo">
${trigger.trigger}
</echo>
</jobs>
</events:trigger>
</job>
</oddjob>
-
Field Summary
Fields inherited from class org.oddjob.framework.extend.StructuralJob
childHelper, destroy, stop, structuralState -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidonImmediateEvent(T value) Do something with an event received immediately before the subscribe method has returned.protected voidonLaterEvent(T value, Object job, Executor executor) Called when an event is received after subscription.protected voidonReset()Allow sub classes to do something on reset.protected voidonSubscriptionStarted(Object job, Executor executor) Called once the subscription has started.protected StateListenerUsed by subclasses to provide a state listener to be added to the child job.Methods inherited from class org.oddjob.events.EventJobBase
accept, execute, getEventSource, getInitialStateOp, getTo, getTrigger, isBeDestination, onStop, postStop, setBeDestination, setEventSource, setExecutorService, setJobs, setTo, setTrigger, startChildStateReflector, switchToChildStateReflector, unsubscribeMethods inherited from class org.oddjob.framework.extend.StructuralJob
addStructuralListener, fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onDestroy, onHardReset, onSoftReset, removeStructuralListener, run, softReset, stateHandler, stop, stopChildStateReflector, waitForChildrenOnStopMethods inherited from class org.oddjob.framework.extend.BasePrimary
configure, getName, logger, logger, loggerName, save, setName, toStringMethods inherited from class org.oddjob.framework.extend.BaseComponent
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSessionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
-
Constructor Details
-
Trigger
public Trigger()
-
-
Method Details
-
onReset
protected void onReset()Description copied from class:StructuralJobAllow sub classes to do something on reset.- Overrides:
onResetin classStructuralJob<Object>
-
onImmediateEvent
Description copied from class:EventJobBaseDo something with an event received immediately before the subscribe method has returned.- Specified by:
onImmediateEventin classEventJobBase<T>- Parameters:
value- The event.
-
onSubscriptionStarted
Description copied from class:EventJobBaseCalled once the subscription has started.- Specified by:
onSubscriptionStartedin classEventJobBase<T>- Parameters:
job- The job to execute if any.executor- The executor to use to execute the job.
-
onLaterEvent
Description copied from class:EventJobBaseCalled when an event is received after subscription. There is no guarantee that this will be called after theEventJobBase.onSubscriptionStarted(Object, Executor)method, implementors are responsible for their own synchronisation if required.- Specified by:
onLaterEventin classEventJobBase<T>- Parameters:
value- The event.
-
stateOnChildComplete
Description copied from class:EventJobBaseUsed by subclasses to provide a state listener to be added to the child job.- Specified by:
stateOnChildCompletein classEventJobBase<T>- Returns:
- A State Listener. Must not be null.
-