PropagationContext context,
InternalWorkingMemory workingMemory) {
final ConditionalBranchMemory memory = (ConditionalBranchMemory) workingMemory.getNodeMemory( this );
boolean wasPropagated = leftTuple.getFirstChild() != null;
ConditionalExecution conditionalExecution = branchEvaluator.evaluate( leftTuple, workingMemory, memory.context );
if ( wasPropagated ) {
LeftTupleSink mainSink = this.sink.getSinks()[0];
LeftTupleSink oldSink = leftTuple.getFirstChild().getSink();
if ( conditionalExecution != null ) {
LeftTupleSink newSink = conditionalExecution.getSink().getSinks()[0];
if ( oldSink.equals(newSink) ) {
// old and new propagation on the same branch sink -> modify
conditionalExecution.getSink().propagateModifyChildLeftTuple( leftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
if ( !conditionalExecution.isBreaking() ) {
this.sink.propagateAssertLeftTuple( leftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
}
} else {
if ( oldSink.equals(mainSink) ) {
// old propagation on main sink
if ( conditionalExecution.isBreaking() ) {
// condition is breaking -> retract on main
this.sink.propagateRetractLeftTuple( leftTuple,
context,
workingMemory );
} else {
// condition not breaking -> also modify main
this.sink.propagateModifyChildLeftTuple( leftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
}
} else {
// old propagation on branch sink -> retract
conditionalExecution.getSink().propagateRetractLeftTuple( leftTuple,
context,
workingMemory );
}
// new propagation on different branch sink -> assert
conditionalExecution.getSink().propagateAssertLeftTuple( leftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
if ( !conditionalExecution.isBreaking() && !oldSink.equals(mainSink) ) {
this.sink.propagateAssertLeftTuple( leftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
}
}
} else {
if ( oldSink.equals(mainSink) ) {
// old and new propagation on main sink -> modify
this.sink.propagateModifyChildLeftTuple( leftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
} else {
// old propagation on branch sink -> retract
this.sink.propagateRetractLeftTuple( leftTuple,
context,
workingMemory );
// new propagation on main sink -> assert
this.sink.propagateAssertLeftTuple( leftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
}
}
} else {
// not propagated -> assert
boolean breaking = false;
if ( conditionalExecution != null ) {
conditionalExecution.getSink().propagateAssertLeftTuple( leftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
breaking = conditionalExecution.isBreaking();
}
if ( !breaking ) {
this.sink.propagateAssertLeftTuple( leftTuple,
context,
workingMemory,