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>