final DataflowQueue stream4 = new DataflowQueue();
// processor1 waits for value in stream 1 and writes 2*value to stream2
final List<DataflowQueue> calculationInputList = asList(stream1);
final List<DataflowQueue> calculationOutputList = asList(stream2);
final DataflowProcessor processor1 = Dataflow.operator(calculationInputList, calculationOutputList, new DataflowMessagingRunnable(1) {
@Override
protected void doRun(final Object... arguments) {
// Passing calculated value to output stream
getOwningProcessor().bindOutput(2 * (Integer) arguments[0]);
}
});
assertFalse("Stream2 should not be bound as no value was passed to stream1", stream2.isBound());
// send values to streams
stream1.bind(1);
waitForValue(stream2);
assertTrue("Stream2 should be bound as value has been calculated by processor1", stream2.isBound());
// processor2 reads value from stream2 and stream 2 and writes sum to stream 4
final DataflowProcessor processor2 = Dataflow.operator(asList(stream2, stream3), asList(stream4), new DataflowMessagingRunnable(2) {
@Override
protected void doRun(final Object... arguments) {
getOwningProcessor().bindOutput((Integer) arguments[0] + (Integer) arguments[1]);
}
});