use of org.drools.core.reteoo.ConditionalBranchEvaluator.ConditionalExecution in project drools by kiegroup.
the class PhreakBranchNode method doLeftUpdates.
public void doLeftUpdates(ConditionalBranchNode branchNode, ConditionalBranchMemory cbm, LeftTupleSink sink, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples, RuleExecutor executor) {
ConditionalBranchEvaluator branchEvaluator = branchNode.getBranchEvaluator();
RuleAgendaItem ruleAgendaItem = executor.getRuleAgendaItem();
int salienceInt = 0;
Salience salience = ruleAgendaItem.getRule().getSalience();
if (!salience.isDynamic()) {
salienceInt = ruleAgendaItem.getRule().getSalience().getValue();
salience = null;
}
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
BranchTuples branchTuples = getBranchTuples(sink, leftTuple);
RuleTerminalNode oldRtn = null;
if (branchTuples.rtnLeftTuple != null) {
oldRtn = branchTuples.rtnLeftTuple.getTupleSink();
}
ConditionalExecution conditionalExecution = branchEvaluator.evaluate(leftTuple, agenda.getWorkingMemory(), 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 (branchTuples.rtnLeftTuple.getMemory() != null) {
executor.removeLeftTuple(branchTuples.rtnLeftTuple);
}
PhreakRuleTerminalNode.doLeftDelete(agenda, executor, branchTuples.rtnLeftTuple);
} else if (newRtn == oldRtn) {
// old and new on same branch, so update
PhreakRuleTerminalNode.doLeftTupleUpdate(newRtn, executor, agenda, salienceInt, salience, branchTuples.rtnLeftTuple);
} else {
// old and new on different branches, delete one and insert the other
if (branchTuples.rtnLeftTuple.getMemory() != null) {
executor.removeLeftTuple(branchTuples.rtnLeftTuple);
}
PhreakRuleTerminalNode.doLeftDelete(agenda, executor, branchTuples.rtnLeftTuple);
branchTuples.rtnLeftTuple = newRtn.createLeftTuple(leftTuple, newRtn, leftTuple.getPropagationContext(), true);
PhreakRuleTerminalNode.doLeftTupleInsert(newRtn, executor, agenda, executor.getRuleAgendaItem(), salienceInt, salience, branchTuples.rtnLeftTuple);
}
} else if (newRtn != null) {
// old does not exist, new exists, so insert
branchTuples.rtnLeftTuple = newRtn.createLeftTuple(leftTuple, newRtn, leftTuple.getPropagationContext(), true);
PhreakRuleTerminalNode.doLeftTupleInsert(newRtn, executor, agenda, executor.getRuleAgendaItem(), salienceInt, salience, branchTuples.rtnLeftTuple);
}
// Handle main branch
if (branchTuples.mainLeftTuple != null) {
normalizeStagedTuples(stagedLeftTuples, branchTuples.mainLeftTuple);
if (!breaking) {
// child exist, new one does, so update
trgLeftTuples.addUpdate(branchTuples.mainLeftTuple);
} else {
// child exist, new one does not, so delete
trgLeftTuples.addDelete(branchTuples.mainLeftTuple);
}
} else if (!breaking) {
// child didn't exist, new one does, so insert
trgLeftTuples.addInsert(sink.createLeftTuple(leftTuple, sink, leftTuple.getPropagationContext(), true));
}
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.reteoo.ConditionalBranchEvaluator.ConditionalExecution in project drools by kiegroup.
the class PhreakBranchNode method doLeftInserts.
public void doLeftInserts(ConditionalBranchNode branchNode, ConditionalBranchMemory cbm, LeftTupleSink sink, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, RuleExecutor executor) {
ConditionalBranchEvaluator branchEvaluator = branchNode.getBranchEvaluator();
RuleAgendaItem ruleAgendaItem = executor.getRuleAgendaItem();
int salienceInt = 0;
Salience salience = ruleAgendaItem.getRule().getSalience();
if (!salience.isDynamic()) {
salienceInt = ruleAgendaItem.getRule().getSalience().getValue();
salience = null;
}
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
boolean breaking = false;
ConditionalExecution conditionalExecution = branchEvaluator.evaluate(leftTuple, agenda.getWorkingMemory(), cbm.context);
boolean useLeftMemory = RuleNetworkEvaluator.useLeftMemory(branchNode, leftTuple);
if (conditionalExecution != null) {
RuleTerminalNode rtn = (RuleTerminalNode) conditionalExecution.getSink().getFirstLeftTupleSink();
LeftTuple branchedLeftTuple = rtn.createLeftTuple(leftTuple, rtn, leftTuple.getPropagationContext(), useLeftMemory);
PhreakRuleTerminalNode.doLeftTupleInsert(rtn, executor, agenda, executor.getRuleAgendaItem(), salienceInt, salience, branchedLeftTuple);
breaking = conditionalExecution.isBreaking();
}
if (!breaking) {
trgLeftTuples.addInsert(sink.createLeftTuple(leftTuple, sink, leftTuple.getPropagationContext(), useLeftMemory));
}
leftTuple.clearStaged();
leftTuple = next;
}
}
Aggregations