Package org.oddjob.beanbus.destinations
Class SplitDestinations<T>
java.lang.Object
org.oddjob.framework.extend.BaseComponent
org.oddjob.framework.extend.BasePrimary
org.oddjob.framework.extend.StructuralJob<Object>
org.oddjob.beanbus.destinations.SplitDestinations<T>
- All Implemented Interfaces:
Flushable,Serializable,Runnable,Consumer<T>,ArooaContextAware,ArooaSessionAware,Forceable,PropertyChangeNotifier,Transient,Iconic,LogEnabled,Resettable,Stateful,Stoppable,Structural
public class SplitDestinations<T>
extends StructuralJob<Object>
implements Transient, Consumer<T>, Flushable
- Author:
- Rob Gordon
- See Also:
Description
A Bean Bus Destination that splits data between child destinations depending on a Strategy.Example
All numbers are passed to two queues for computation of the Fibonacci Sequence of the number, and the Factorial.
<oddjob>
<job>
<sequential>
<jobs>
<script id="funcs">function fibonacci(x) {
if (x<1) return new java.lang.Integer(0)
if (x==1) return new java.lang.Integer(1)
return new java.lang.Integer(fibonacci(x-1) + fibonacci(x-2))
}
function factorial(x) {
if (x<1) return new java.lang.Integer(0)
if (x==1) return new java.lang.Integer(1)
return new java.lang.Integer(factorial(x-1) *x)
}
</script>
<parallel id="parallel">
<jobs>
<bus:bus name="Fibonacci Bus" xmlns:bus="oddjob:beanbus">
<of>
<bus:driver>
<values>
<value value="${fibonacciQueue}"/>
</values>
</bus:driver>
<bus:map name="Fibonacci">
<function>
<value value="${funcs.function(fibonacci)}"/>
</function>
</bus:map>
<bus:collect id="fibonacci"/>
</of>
</bus:bus>
<bus:bus name="Factorial Bus" xmlns:bus="oddjob:beanbus">
<of>
<bus:driver>
<values>
<value value="${factorialQueue}"/>
</values>
</bus:driver>
<bus:map name="Factorial">
<function>
<value value="${funcs.function(factorial)}"/>
</function>
</bus:map>
<bus:collect id="factorial"/>
</of>
</bus:bus>
<bus:bus xmlns:bus="oddjob:beanbus">
<of>
<bus:driver>
<values>
<sequence from="1" to="5"/>
</values>
</bus:driver>
<bean class="org.oddjob.beanbus.destinations.SplitDestinations">
<strategy>
<bean class="org.oddjob.beanbus.destinations.SplitDestinations$All"/>
</strategy>
<of>
<bus:queue id="fibonacciQueue" name="FibonacciQueue"/>
<bus:queue id="factorialQueue" name="FactorialQueue"/>
</of>
</bean>
</of>
</bus:bus>
</jobs>
</parallel>
<folder name="Test the Funcs">
<jobs>
<echo name="Test Fibonacci">#{funcs.getFunction('fibonacci').apply(3)}</echo>
<echo name="Test Factorial">#{funcs.getFunction('factorial').apply(6)}</echo>
</jobs>
</folder>
</jobs>
</sequential>
</job>
</oddjob>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
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()getCount()protected StateOperatorSubclasses must provide theStateOperatorthat will decide how to evaluate the children's state.protected voidonReset()Allow sub classes to do something on reset.voidAdd a child.voidMethods inherited from class org.oddjob.framework.extend.StructuralJob
addStructuralListener, fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onDestroy, onHardReset, onSoftReset, onStop, 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
-
SplitDestinations
public SplitDestinations()
-
-
Method Details
-
execute
Description copied from class:StructuralJobExecute this job.- Specified by:
executein classStructuralJob<Object>- Throws:
InterruptedExceptionExecutionException
-
accept
-
flush
- Specified by:
flushin interfaceFlushable- Throws:
IOException
-
onReset
protected void onReset()Description copied from class:StructuralJobAllow sub classes to do something on reset.- Overrides:
onResetin classStructuralJob<Object>
-
setOf
Add a child.- Parameters:
child- A child- Reference Property:
- of
- Required:
- No, but pointless if missing.
Description
The components of a Bus. -
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.
-
getStrategy
-
setStrategy
-
getCount
-