InternalWorkingMemory wm,
LeftTupleSets srcLeftTuples,
LeftTupleSets trgLeftTuples,
LeftTupleSets stagedLeftTuples, RuleNetworkEvaluatorActivation activation) {
ConditionalBranchEvaluator branchEvaluator = branchNode.getBranchEvaluator();
LeftTupleList tupleList = activation.getLeftTupleList();
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
LeftTuple rtnLeftTuple = (LeftTuple) leftTuple.getObject();
LeftTuple mainLeftTuple = leftTuple.getFirstChild();
RuleTerminalNode oldRtn = null;
if (rtnLeftTuple != null) {
oldRtn = (RuleTerminalNode) rtnLeftTuple.getSink();
}
ConditionalExecution conditionalExecution = branchEvaluator.evaluate(leftTuple, wm, cbm.context);
RuleTerminalNode newRtn = null;
boolean breaking = false;
if (conditionalExecution != null) {
newRtn = (RuleTerminalNode) conditionalExecution.getSink().getFirstLeftTupleSink();
breaking = conditionalExecution.isBreaking();
}
// Handle conditional branches
if (oldRtn != null) {
if (newRtn == null) {
// old exits, new does not, so delete
if ( rtnLeftTuple.getMemory() != null ) {
tupleList.remove(rtnLeftTuple);
}
oldRtn.retractLeftTuple(rtnLeftTuple, rtnLeftTuple.getPropagationContext(), wm);
} else if (newRtn == oldRtn) {
// old and new on same branch, so update
if ( rtnLeftTuple.getMemory() != null ) {
tupleList.remove(rtnLeftTuple); // must be removed before it can bereadded
}
tupleList.add(rtnLeftTuple);
//oldRtn.modifyLeftTuple(rtnLeftTuple, rtnLeftTuple.getPropagationContext(), wm);
} else {
// old and new on different branches, delete one and insert the other
if ( rtnLeftTuple.getMemory() != null ) {
tupleList.remove(rtnLeftTuple);
}
oldRtn.retractLeftTuple(rtnLeftTuple, rtnLeftTuple.getPropagationContext(), wm);
rtnLeftTuple = newRtn.createLeftTuple(leftTuple,
newRtn,
leftTuple.getPropagationContext(), true);
leftTuple.setObject(rtnLeftTuple);
tupleList.add(rtnLeftTuple);
//newRtn.assertLeftTuple(rtnLeftTuple, rtnLeftTuple.getPropagationContext(), wm);
}
} else if (newRtn != null) {
// old does not exist, new exists, so insert
rtnLeftTuple = newRtn.createLeftTuple(leftTuple,
newRtn,
leftTuple.getPropagationContext(), true);
leftTuple.setObject(rtnLeftTuple);
//newRtn.assertLeftTuple(rtnLeftTuple, rtnLeftTuple.getPropagationContext(), wm);
tupleList.add(rtnLeftTuple);
}
// Handle main branch
if (mainLeftTuple != null) {
switch (mainLeftTuple.getStagedType()) {