Class BasicBusService

All Implemented Interfaces:
Flushable, Serializable, Runnable, Consumer<Object>, ArooaContextAware, ArooaSessionAware, ServiceProvider, ConductorServiceProvider, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resettable, Stateful, Stoppable, Structural

public class BasicBusService extends StructuralJob<Object> implements ConductorServiceProvider, Consumer<Object>, Flushable
Author:
Rob Gordon
See Also:

Description

Links components in a data pipeline. Components provide data by accepting an Consumer either by being an Outbound or by marking a setter with the Destination annotation. Components accept data by being a Consumer. Components can be both.

This component parent provides the following features over other component parents such as SequentialJob:

  • Components will be automatically linked to the next component unless this is disabled.
  • Any plain Consumer will appear in the bus as a service with appropriate icons and state.
  • Components will be run (or started) in reverse order so destinations are ready to receive data before it is sent by the previous components.
  • Components will be stopped in order so components that send data are stopped before the destinations that receive the data.
  • If a component has a property setter of type AutoCloseable then one will be set automatically allowing the component to stop the bus.
  • If a component has a property setter of type Flushable then one will be set automatically allowing the component to flush the bus.
  • Any component that is Flushable will be flushed when a component flushes the bus. Flush will be called in component order. Flush will always be called when the bus stops, unless it crashes.
  • If a component wishes to both stop and flush the bus, and doesn't mind a dependency on this framework it can provide a property setter of type BusConductor and one will be set automatically
  • If a component enters an Exception state the bus will crash. Other components will be stopped in order.

Example

A simple bus of 3 components. The first component is the bus driver that sends 3 beans down the pipe. The second component is a function that doubles the price and the last component collects the results.

<oddjob>

    <job>

        <bus:bus id="bean-bus" xmlns:bus="oddjob:beanbus">

            <of>

                <bus:driver>

                    <values>

                        <list>

                            <values>

                                <value value="#{25.5}"/>

                                <value value="#{36.2}"/>

                                <value value="#{40.4}"/>

                            </values>

                        </list>

                    </values>

                </bus:driver>

                <bus:map>

                    <function>

                        <value value="#{ function(x) { return x * 2 } }"/>

                    </function>

                </bus:map>

                <bus:collect id="results"/>

            </of>

        </bus:bus>

    </job>

</oddjob>
Shows how a bus can be nested to create side branches. The data is passed to each branch in turn.

<oddjob>

    <job>

        <cascade>

            <jobs>

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

                    <of>

                        <bus:driver>

                            <values>

                                <list>

                                    <values>

                                        <value value="red"/>

                                        <value value="red"/>

                                        <value value="blue"/>

                                        <value value="green"/>

                                    </values>

                                </list>

                            </values>

                        </bus:driver>

                        <bus:bus>

                            <of>

                                <bus:filter id="filterRed">

                                    <predicate>

                                        <value value="#{ function(x) { return 'red' == x }}"/>

                                    </predicate>

                                </bus:filter>

                            </of>

                        </bus:bus>

                        <bus:bus>

                            <of>

                                <bus:filter id="filterBlue">

                                    <predicate>

                                        <value value="#{ function(x) { return 'blue' == x }}"/>

                                    </predicate>

                                </bus:filter>

                            </of>

                        </bus:bus>

                    </of>

                </bus:bus>

                <check value="${filterRed.passed}" eq="2"/>

                <check value="${filterBlue.passed}" eq="1"/>

            </jobs>

        </cascade>

    </job>

</oddjob>
  • Constructor Details

    • BasicBusService

      public BasicBusService()
      Only constructor.
  • Method Details