Class When<T>

All Implemented Interfaces:
Serializable, Runnable, Consumer<T>, ArooaContextAware, ArooaSessionAware, Outbound<T>, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resettable, Stateful, Stoppable, Structural

public class When<T> extends EventJobBase<T>
Author:
Rob Gordon.
See Also:

Description

Runs a job when triggered by the arrival of an event. The job will be re-run every time the event arrives. If the job is still running when a new event arrives, the job will attempt to be stopped and rerun. A typical use case would be processing a file when it arrives, but which may be re-sent with more up-to-date information.

Example

Evaluating greengrocer portfolios of fruit when data arrives.

<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>
Being a destination in a pipeline.

<oddjob>

    <job>

        <sequential>

            <jobs>

                <bus:bus xmlns:bus="oddjob:beanbus">

                    <of>

                        <bean class="org.oddjob.events.WhenTest$PretendFileWatcher" id="fileWatcher"/>

                        <bus:filter id="filter">

                            <predicate>

                                <bean class="org.oddjob.events.WhenTest$OnlyTxtFiles"/>

                            </predicate>

                        </bus:filter>

                        <events:when beDestination="true" id="when" xmlns:events="oddjob:events">

                            <jobs>

                                <echo id="result">

                                    Result: ${when.trigger}

                                </echo>

                            </jobs>

                        </events:when>

                    </of>

                </bus:bus>

                <folder>

                    <jobs>

                        <set id="set1" name="Set File Name 1">

                            <values>

                                <value key="fileWatcher.someFileName" value="Fruit.txt"/>

                            </values>

                        </set>

                        <set id="set2" name="Set File Name 2">

                            <values>

                                <value key="fileWatcher.someFileName" value="Names.doc"/>

                            </values>

                        </set>

                        <set id="set3" name="Set File Name 3">

                            <values>

                                <value key="fileWatcher.someFileName" value="Prices.txt"/>

                            </values>

                        </set>

                    </jobs>

                </folder>

            </jobs>

        </sequential>

    </job>

</oddjob>
  • Constructor Details

    • When

      public When()
  • Method Details