Package org.oddjob.events
Class ForEvents<T>
- All Implemented Interfaces:
Runnable,ArooaContextAware,ArooaSessionAware,ConfigurationOwner,Outbound<CompositeEvent<T>>,PropertyChangeNotifier,Iconic,LogEnabled,Resettable,Stateful,Stoppable,Structural
public class ForEvents<T>
extends EventServiceBase<CompositeEvent<T>>
implements Structural, ConfigurationOwner
Description
An Event Source For a variable set of child Event Sources. Required when the list of events to wait for changes dynamically - such as the set of files required to run a job.Example
Wait for prices to be available to price some fruit trades. This resulted as an experiment in turning Oddjob into a rules engine.
<oddjob id="oddjob">
<job>
<sequential>
<jobs>
<properties name="Properties">
<values>
<file file="${oddjob.dir}/data" key="data.dir"/>
</values>
</properties>
<bean class="org.oddjob.events.example.FileFactStore" id="factStore" rootDir="${data.dir}"/>
<events:when id="whenBookList" name="When BookList Available" xmlns:events="oddjob:events">
<jobs>
<bean class="org.oddjob.events.example.FactSubscriber" factStore="${factStore}" name="Subscribe to BookList" query="BookList:GREENGROCERS"/>
<foreach id="forEachBook" name="For Each Book">
<values>
<value value="${whenBookList.trigger.of.books}"/>
</values>
<configuration>
<inline>
<foreach id="bookName">
<job>
<events:when id="whenBook" name="When ${bookName.current}">
<jobs>
<bean class="org.oddjob.events.example.FactSubscriber" factStore="${factStore}" name="Subscribe to Book ${bookName.current}" query="Book:${bookName.current}"/>
<events:when id="priceMatch" name="When Prices for ${bookName.current}">
<jobs>
<events:for name="For Each Trade">
<configuration>
<inline>
<events id="trade">
<job>
<bean class="org.oddjob.events.example.FactSubscriber" factStore="${factStore}" name="Subscribe to Price for ${trade.current.product}" query="Price:${trade.current.product}"/>
</job>
</events>
</inline>
</configuration>
<values>
<value value="${whenBook.trigger.of.trades}"/>
</values>
</events:for>
<sequential name="Run Calculation">
<jobs>
<bean class="org.oddjob.events.example.ValueCalculator" id="calculate">
<trades>
<value value="${whenBook.trigger.of.trades}"/>
</trades>
<prices>
<value value="${priceMatch.trigger.ofs}"/>
</prices>
</bean>
<echo>Value of ${bookName.current} is ${calculate.value}</echo>
</jobs>
</sequential>
</jobs>
</events:when>
</jobs>
</events:when>
</job>
</foreach>
</inline>
</configuration>
</foreach>
</jobs>
</events:when>
</jobs>
</sequential>
</job>
</oddjob>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThis provides a bean for current properties. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ChildHelper<Object> Track changes to children and notify listeners.static final ArooaElementRoot element for configuration. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOwnerStateListener(OwnerStateListener listener) Add a listener.voidaddStructuralListener(StructuralListener listener) Add a listener.doStart(Consumer<? super CompositeEvent<T>> consumer) getFile()intgetIndex()getLast()intprotected ObjectloadConfigFor(Object value) Load a configuration for a single value.protected voidSubclasses override this method to clear up resources.protected voidonReset()Allow sub classes to do something on reset.protected voidpreLoad()Setup and load the first jobs.Provide aConfigurationSession.voidremoveOwnerStateListener(OwnerStateListener listener) Remove a listener.voidremoveStructuralListener(StructuralListener listener) Remove a listener.Get the design factory for the configuration.Get the root element.voidsetConfiguration(ArooaConfiguration configuration) voidsetEventOperator(EventOperator<T> eventOperator) voidvoidsetPurgeAfter(int purgeAfter) voidAdd a type.Methods inherited from class org.oddjob.events.EventServiceBase
fireDestroyedState, getStateChanger, hardReset, iconHelper, onHardReset, onSoftReset, run, setStateException, setTo, softReset, stateHandler, stopMethods 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
-
Field Details
-
FOREACH_ELEMENT
Root element for configuration. -
childHelper
Track changes to children and notify listeners.
-
-
Constructor Details
-
ForEvents
public ForEvents()Constructor.
-
-
Method Details
-
setValues
Add a type. This will be called during parsing by the handler to add a type for each element.- Parameters:
values- The type.
-
addStructuralListener
Add a listener. The listener will immediately receive add notifications for all existing children.- Specified by:
addStructuralListenerin interfaceStructural- Parameters:
listener- The listener.
-
removeStructuralListener
Remove a listener.- Specified by:
removeStructuralListenerin interfaceStructural- Parameters:
listener- The listener.
-
provideConfigurationSession
Description copied from interface:ConfigurationOwnerProvide aConfigurationSession.- Specified by:
provideConfigurationSessionin interfaceConfigurationOwner- Returns:
- A
ConfigurationSession. May be null if no session is available.
-
addOwnerStateListener
Description copied from interface:ConfigurationOwnerAdd a listener.- Specified by:
addOwnerStateListenerin interfaceConfigurationOwner- Parameters:
listener-
-
removeOwnerStateListener
Description copied from interface:ConfigurationOwnerRemove a listener.- Specified by:
removeOwnerStateListenerin interfaceConfigurationOwner- Parameters:
listener-
-
rootDesignFactory
Description copied from interface:ConfigurationOwnerGet the design factory for the configuration. If this is null the Oddjob Explorer won't show a DesignInside action.Note that this is a
SerializableDesignFactoryso that this interface can be represented remotely.- Specified by:
rootDesignFactoryin interfaceConfigurationOwner- Returns:
- A DesignFactory. Must not be null if a
ConfigurationSessionis available.
-
rootElement
Description copied from interface:ConfigurationOwnerGet the root element.- Specified by:
rootElementin interfaceConfigurationOwner- Returns:
- The root element of the configuration. Must not be null if
a
ConfigurationSessionis available.
-
loadConfigFor
Load a configuration for a single value.- Parameters:
value-- Throws:
ArooaParseException
-
preLoad
Setup and load the first jobs.if
preLoad()is 0 all will be loaded otherwise up to that number will be loaded.- Throws:
ArooaParseException
-
doStart
- Specified by:
doStartin classEventServiceBase<CompositeEvent<T>>
-
getIndex
public int getIndex()- Returns:
- Returns the index.
-
getEventOperator
-
setEventOperator
-
getLast
-
onReset
protected void onReset()Description copied from class:EventServiceBaseAllow sub classes to do something on reset.- Overrides:
onResetin classEventServiceBase<CompositeEvent<T>>
-
onDestroy
protected void onDestroy()Description copied from class:BaseComponentSubclasses override this method to clear up resources. This is called by the framework before child elements have been destroyed.- Overrides:
onDestroyin classBaseComponent
-
setFile
- Reference Property:
- file
- Required:
- No.
Description
The name of the configuration file. to use for configuration. -
getFile
-
getConfiguration
-
setConfiguration
-
getPurgeAfter
public int getPurgeAfter() -
setPurgeAfter
public void setPurgeAfter(int purgeAfter)
-