Package org.oddjob.beanbus.bus
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:
- Components will be automatically linked to the next component unless this is disabled.
- Any plain
Consumerwill 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
AutoCloseablethen one will be set automatically allowing the component to stop the bus. - If a component has a property setter of type
Flushablethen one will be set automatically allowing the component to flush the bus. - Any component that is
Flushablewill 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
BusConductorand one will be set automatically - If a component enters an Exception state the bus will crash. Other components will be stopped in order.
Description
Links components in a data pipeline. Components provide data by accepting anConsumer 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:
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>
-
Field Summary
Fields inherited from class org.oddjob.framework.extend.StructuralJob
childHelper, destroy, stop, structuralState -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidexecute()Execute this job.voidflush()intgetCount()protected StateOperatorSubclasses must provide theStateOperatorthat will decide how to evaluate the children's state.Provider the services.getTo()booleanprotected voidmaybeSetConsumerOnOutbound(Object maybeOutbound, Consumer<?> consumer) protected voidonReset()Allow sub classes to do something on reset.protected voidonStop()Allow sub classes to do something on stop.voidsetBusConductor(BusConductor busConductor) voidsetNoAutoLink(boolean noAutoLink) voidAdd a child.voidMethods inherited from class org.oddjob.framework.extend.StructuralJob
addStructuralListener, fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onDestroy, onHardReset, onSoftReset, postStop, removeStructuralListener, run, softReset, startChildStateReflector, 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
-
BasicBusService
public BasicBusService()Only constructor.
-
-
Method Details
-
getInitialStateOp
Description copied from class:StructuralJobSubclasses must provide theStateOperatorthat will decide how to evaluate the children's state.- Specified by:
getInitialStateOpin classStructuralJob<Object>- Returns:
- A State Operator. Must not be null.
-
setOf
Add a child.- Parameters:
child- A child- Reference Property:
- of
- Required:
- No, but pointless if missing.
Description
The components of a Bus. -
execute
Description copied from class:StructuralJobExecute this job.- Specified by:
executein classStructuralJob<Object>- Throws:
Exception- If the unexpected occurs.
-
maybeSetConsumerOnOutbound
-
accept
-
onReset
protected void onReset()Description copied from class:StructuralJobAllow sub classes to do something on reset.- Overrides:
onResetin classStructuralJob<Object>
-
onStop
Description copied from class:StructuralJobAllow sub classes to do something on stop.- Overrides:
onStopin classStructuralJob<Object>- Throws:
FailedToStopException
-
flush
public void flush() -
getServices
Description copied from interface:ServiceProviderProvider the services.- Specified by:
getServicesin interfaceConductorServiceProvider- Specified by:
getServicesin interfaceServiceProvider- Returns:
- The services. May be null.
- Reference Property:
- services
- Required:
- Read Only.
Description
Provides services to other components of a bus. Exposed for advance use only. -
getBusConductor
-
setBusConductor
-
isNoAutoLink
public boolean isNoAutoLink() -
setNoAutoLink
public void setNoAutoLink(boolean noAutoLink) -
getTo
-
setTo
-
getCount
public int getCount()
-