use of org.drools.core.phreak.RuleExecutor in project drools by kiegroup.
the class RuleTerminalNode method cancelMatch.
public void cancelMatch(AgendaItem match, InternalWorkingMemoryActions workingMemory) {
match.cancel();
if (match.isQueued()) {
Tuple leftTuple = match.getTuple();
if (match.getRuleAgendaItem() != null) {
// phreak must also remove the LT from the rule network evaluator
if (leftTuple.getMemory() != null) {
leftTuple.getMemory().remove(leftTuple);
}
}
RuleExecutor ruleExecutor = ((RuleTerminalNodeLeftTuple) leftTuple).getRuleAgendaItem().getRuleExecutor();
PhreakRuleTerminalNode.doLeftDelete(ruleExecutor.getPathMemory().getActualAgenda(workingMemory), ruleExecutor, leftTuple);
}
}
use of org.drools.core.phreak.RuleExecutor in project drools by kiegroup.
the class LinkingTest method testSubnetwork.
@Test
public void testSubnetwork() throws Exception {
String str = "";
str += "package org.kie \n";
str += "import " + A.class.getCanonicalName() + "\n";
str += "import " + B.class.getCanonicalName() + "\n";
str += "import " + C.class.getCanonicalName() + "\n";
str += "import " + D.class.getCanonicalName() + "\n";
str += "import " + E.class.getCanonicalName() + "\n";
str += "import " + F.class.getCanonicalName() + "\n";
str += "import " + G.class.getCanonicalName() + "\n";
str += "global java.util.List list \n";
str += "rule rule1 when \n";
str += " $a : A() \n";
str += " exists ( B() and C() ) \n";
str += " $e : D() \n";
str += "then \n";
str += " list.add( 'x' ); \n";
str += "end \n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
ObjectTypeNode aotn = getObjectTypeNode(kbase, A.class);
ObjectTypeNode botn = getObjectTypeNode(kbase, A.class);
ObjectTypeNode cotn = getObjectTypeNode(kbase, A.class);
InternalWorkingMemory wm = ((StatefulKnowledgeSessionImpl) kbase.newKieSession());
List list = new ArrayList();
wm.setGlobal("list", list);
wm.insert(new A());
wm.insert(new B());
for (int i = 0; i < 28; i++) {
wm.insert(new C());
}
wm.insert(new D());
wm.flushPropagations();
InternalAgenda agenda = (InternalAgenda) wm.getAgenda();
InternalAgendaGroup group = (InternalAgendaGroup) agenda.getNextFocus();
AgendaItem item = (AgendaItem) group.remove();
RuleExecutor ruleExecutor = ((RuleAgendaItem) item).getRuleExecutor();
int count = ruleExecutor.evaluateNetworkAndFire(wm, null, 0, -1);
// assertEquals(3, count );
wm.fireAllRules();
assertEquals(1, list.size());
wm.fireAllRules();
// check it doesn't double fire
assertEquals(1, list.size());
}
use of org.drools.core.phreak.RuleExecutor 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;
}
use of org.drools.core.phreak.RuleExecutor in project drools by kiegroup.
the class DefaultAgenda method evaluateEagerList.
public void evaluateEagerList() {
while (!eager.isEmpty()) {
RuleAgendaItem item = eager.removeFirst();
if (item.isRuleInUse()) {
// this rule could have been removed by an incremental compilation
evaluateQueriesForRule(item);
RuleExecutor ruleExecutor = item.getRuleExecutor();
ruleExecutor.evaluateNetwork(this);
}
}
}
use of org.drools.core.phreak.RuleExecutor in project drools by kiegroup.
the class DefaultAgenda method clearAndCancelActivationGroup.
/*
* (non-Javadoc)
*
* @see org.kie.common.AgendaI#clearActivationGroup(org.kie.spi.ActivationGroup)
*/
public void clearAndCancelActivationGroup(final InternalActivationGroup activationGroup) {
final EventSupport eventsupport = this.workingMemory;
activationGroup.setTriggeredForRecency(this.workingMemory.getFactHandleFactory().getRecency());
for (final Iterator it = activationGroup.iterator(); it.hasNext(); ) {
final ActivationGroupNode node = (ActivationGroupNode) it.next();
final Activation activation = node.getActivation();
activation.setActivationGroupNode(null);
if (activation.isQueued()) {
activation.setQueued(false);
activation.remove();
RuleExecutor ruleExec = ((RuleTerminalNodeLeftTuple) activation).getRuleAgendaItem().getRuleExecutor();
ruleExec.removeLeftTuple((LeftTuple) activation);
eventsupport.getAgendaEventSupport().fireActivationCancelled(activation, this.workingMemory, MatchCancelledCause.CLEAR);
}
}
activationGroup.reset();
}
Aggregations