use of org.drools.core.reteoo.RuleTerminalNodeLeftTuple in project drools by kiegroup.
the class PhreakRuleTerminalNode method doLeftDelete.
public static void doLeftDelete(InternalAgenda agenda, RuleExecutor executor, Tuple leftTuple) {
PropagationContext pctx = leftTuple.getPropagationContext();
pctx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, pctx);
RuleTerminalNodeLeftTuple rtnLt = (RuleTerminalNodeLeftTuple) leftTuple;
rtnLt.setMatched(false);
agenda.cancelActivation(leftTuple, pctx, rtnLt, rtnLt.getTerminalNode());
if (leftTuple.getMemory() != null) {
// Expiration propagations should not be removed from the list, as they still need to fire
executor.removeLeftTuple(leftTuple);
}
leftTuple.setContextObject(null);
}
use of org.drools.core.reteoo.RuleTerminalNodeLeftTuple in project drools by kiegroup.
the class PhreakRuleTerminalNode method doLeftTupleUpdate.
public static void doLeftTupleUpdate(TerminalNode rtnNode, RuleExecutor executor, InternalAgenda agenda, int salienceInt, Salience salience, LeftTuple leftTuple) {
PropagationContext pctx = leftTuple.getPropagationContext();
pctx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, pctx);
boolean blocked = false;
RuleTerminalNodeLeftTuple rtnLeftTuple = (RuleTerminalNodeLeftTuple) leftTuple;
if (executor.isDeclarativeAgendaEnabled()) {
if (rtnLeftTuple.getBlockers() != null && !rtnLeftTuple.getBlockers().isEmpty()) {
// declarativeAgenda still blocking LeftTuple, so don't add back ot list
blocked = true;
}
} else {
blocked = rtnNode.getRule().isNoLoop() && rtnNode.equals(pctx.getTerminalNodeOrigin());
}
InternalWorkingMemory wm = agenda.getWorkingMemory();
if (salience != null) {
salienceInt = salience.getValue(new DefaultKnowledgeHelper(rtnLeftTuple, wm), rtnNode.getRule(), wm);
}
if (agenda.getActivationsFilter() != null && !agenda.getActivationsFilter().accept(rtnLeftTuple, wm, rtnNode)) {
// only relevant for serialization, to not re-fire Matches already fired
return;
}
if (!blocked) {
boolean addToExector = true;
if (rtnNode.getRule().isLockOnActive() && pctx.getType() != PropagationContext.Type.RULE_ADDITION) {
long handleRecency = pctx.getFactHandle().getRecency();
InternalAgendaGroup agendaGroup = executor.getRuleAgendaItem().getAgendaGroup();
if (blockedByLockOnActive(rtnNode.getRule(), pctx, handleRecency, agendaGroup)) {
addToExector = false;
}
}
if (addToExector) {
if (!rtnLeftTuple.isQueued()) {
// not queued, so already fired, so it's effectively recreated
EventSupport es = (EventSupport) wm;
es.getAgendaEventSupport().fireActivationCreated(rtnLeftTuple, wm);
rtnLeftTuple.update(salienceInt, pctx);
executor.addLeftTuple(leftTuple);
wm.getRuleEventSupport().onUpdateMatch(rtnLeftTuple);
}
}
} else {
// LeftTuple is blocked, and thus not queued, so just update it's values
rtnLeftTuple.update(salienceInt, pctx);
}
if (!rtnNode.isFireDirect() && executor.isDeclarativeAgendaEnabled()) {
agenda.modifyActivation(rtnLeftTuple, rtnLeftTuple.isQueued());
}
}
use of org.drools.core.reteoo.RuleTerminalNodeLeftTuple in project drools by kiegroup.
the class RuleExecutor method cancel.
public void cancel(InternalWorkingMemory wm, EventSupport es) {
while (!tupleList.isEmpty()) {
RuleTerminalNodeLeftTuple rtnLt = (RuleTerminalNodeLeftTuple) tupleList.removeFirst();
if (queue != null) {
queue.dequeue(rtnLt);
}
es.getAgendaEventSupport().fireActivationCancelled(rtnLt, wm, MatchCancelledCause.CLEAR);
}
}
use of org.drools.core.reteoo.RuleTerminalNodeLeftTuple in project drools by kiegroup.
the class TraitTest method testTupleIntegrityOnModification.
@Test
public void testTupleIntegrityOnModification() {
String drl = "package test " + "import " + Entity.class.getName() + ";" + "global java.util.List list; " + "declare trait A @propertyReactive value : int end " + "rule Trait when " + " $core: Entity( ) " + "then " + " A o = don( $core, A.class ); " + " System.out.println( 'Found ! ' + o ); " + "end " + "rule Test when " + " $x: A( value == 0 ) " + "then " + " list.add( 0 ); " + "end " + "rule Check when " + " $x: A( value == 42 ) " + "then " + " list.add( 42 ); " + "end " + "rule Mood when " + " $x : A( value != 42 ) " + "then " + " modify ( $x ) { setValue( 42 ); } " + "end ";
KieBase kbase = getKieBaseFromString(drl);
TraitFactory.setMode(mode, kbase);
KieSession ksession = kbase.newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.insert(new Entity());
ksession.fireAllRules();
for (final Object o : ksession.getObjects(new ObjectFilter() {
@Override
public boolean accept(Object object) {
return object.getClass().getName().contains("test.A");
}
})) {
InternalFactHandle handle = (InternalFactHandle) ksession.getFactHandle(o);
LeftTuple first = handle.getFirstLeftTuple();
assertTrue(first instanceof RuleTerminalNodeLeftTuple);
assertEquals("Check", ((RuleTerminalNodeLeftTuple) first).getRule().getName());
}
assertEquals(Arrays.asList(0, 42), list);
}
use of org.drools.core.reteoo.RuleTerminalNodeLeftTuple in project drools by kiegroup.
the class DefaultAgenda method isRuleInstanceAgendaItem.
public boolean isRuleInstanceAgendaItem(String ruleflowGroupName, String ruleName, long processInstanceId) {
propagationList.flush();
RuleFlowGroup systemRuleFlowGroup = this.getRuleFlowGroup(ruleflowGroupName);
Match[] matches = ((InternalAgendaGroup) systemRuleFlowGroup).getActivations();
for (Match match : matches) {
Activation act = (Activation) match;
if (act.isRuleAgendaItem()) {
// The lazy RuleAgendaItem must be fully evaluated, to see if there is a rule match
RuleExecutor ruleExecutor = ((RuleAgendaItem) act).getRuleExecutor();
ruleExecutor.evaluateNetwork(this);
TupleList list = ruleExecutor.getLeftTupleList();
for (RuleTerminalNodeLeftTuple lt = (RuleTerminalNodeLeftTuple) list.getFirst(); lt != null; lt = (RuleTerminalNodeLeftTuple) lt.getNext()) {
if (ruleName.equals(lt.getRule().getName())) {
if (checkProcessInstance(lt, processInstanceId)) {
return true;
}
}
}
} else {
if (ruleName.equals(act.getRule().getName())) {
if (checkProcessInstance(act, processInstanceId)) {
return true;
}
}
}
}
return false;
}
Aggregations