I posted the question because of monitoring, but didn't make it clear. The scenario is: a monitor in the second branch after a split modifies a processor token in the first branch. What will be the execution order? branch1 -> monitor commands or monitor -> branch1
I think you have the wrong idea of what a monitor does. The commands inside a monitor are only executed in response to activity on its producer, i.e. when data is created, not when the Java code handles the monitor function. If I am interpreting your question correctly, the answer is, "Not relevant".
Yes, I meant execution on the board, not in the Java code that creates the route. For example, does the Subtract op complete before the monitor body in the 2nd branch, or vice versa?
.process(new Counter()).split() .branch() .process("X", new Maths(Maths.Operation.SUBTRACT, 0)).log("V")
.branch() .monitor(new DataSignal.ActivityHandler() { @Override public void onSignalActive(Map<String, DataProcessor> map, DataSignal.DataToken dataToken) { map.get("X").modifyConfiguration( new Maths(Maths.Operation.SUBTRACT, dataToken)); } }) .end();
Ok I see what you are doing. Modifying a processor will always occur before the processor handles the next piece of data. So, your counter will trigger the modification of processor X, then processor X will deal with the data from the counter processor, competing the feedfoward loop.
Unless the code snippet is incomplete, your chain can be rewritten as:
.process(new Counter()).monitor(...).process("X", new Maths(...));
Branches are only needed if you want to chain different processors onto a data producer.
So, in this toy example the monitor gets triggered first and the "V" log will contain a stream of 0s, If S is the data produced by the counter - V = S(t) - S(t)
But if I chain a dummy processor just before the monitor, it now creates a feedback loop and V becomes S(t) - S(t - 1) - a stream of 1s in the log file. So in this case the modification of X occurs after X is executed. That's why I wanted some insight into execution ordering across branches.
.process(new Counter()).split() .branch() .process("X", new Maths(Maths.Operation.SUBTRACT, 0)).log("V") .branch() .process( new Maths(Maths.Operation.SUBTRACT, 0)) .monitor(new DataSignal.ActivityHandler() { @Override public void onSignalActive(Map<String, DataProcessor> map, DataSignal.DataToken dataToken) { map.get("X").modifyConfiguration( new Maths(Maths.Operation.SUBTRACT, dataToken)); } }) .end();
Sorry, I had left out some bits of information in the previous post. Processors are executed in the order they are added. In the first example, the processors in order are: 1) counter 2) maths. So, the counter will execute first, trigger the activity monitor to reconfigure the maths processor (X), then execute the maths processor.
For your second example, the processors are added in the order: 1) counter, 2) maths (X), 3) dummy maths. In this case, your monitor is attached to the dummy maths processor so it will not trigger the reconfiguration of processor X in time. To get the correct order, you should swap the branches so the dummy maths processor is added before processor X.
Comments
The scenario is: a monitor in the second branch after a split modifies a processor token in the first branch.
What will be the execution order?
branch1 -> monitor commands or
monitor -> branch1
For example, does the Subtract op complete before the monitor body in the 2nd branch, or vice versa?
But if I chain a dummy processor just before the monitor, it now creates a feedback loop and V becomes
S(t) - S(t - 1) - a stream of 1s in the log file. So in this case the modification of X occurs after X is executed.
That's why I wanted some insight into execution ordering across branches.
.process(new Counter()).split()
.branch()
.process("X", new Maths(Maths.Operation.SUBTRACT, 0)).log("V")
.branch()
.process( new Maths(Maths.Operation.SUBTRACT, 0))
.monitor(new DataSignal.ActivityHandler() {
@Override
public void onSignalActive(Map<String, DataProcessor> map, DataSignal.DataToken dataToken) {
map.get("X").modifyConfiguration(
new Maths(Maths.Operation.SUBTRACT, dataToken));
}
})
.end();