use of org.drools.core.reteoo.TerminalNode in project drools by kiegroup.
the class RuleNetworkEvaluator method evaluateNetwork.
public void evaluateNetwork(PathMemory pmem, RuleExecutor executor, InternalAgenda agenda) {
SegmentMemory[] smems = pmem.getSegmentMemories();
int smemIndex = 0;
// 0
SegmentMemory smem = smems[smemIndex];
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) smem.getRootNode();
LinkedList<StackEntry> stack = new LinkedList<StackEntry>();
NetworkNode node;
Memory nodeMem;
long bit = 1;
if (liaNode == smem.getTipNode()) {
// segment only has liaNode in it
// nothing is staged in the liaNode, so skip to next segment
// 1
smem = smems[++smemIndex];
node = smem.getRootNode();
nodeMem = smem.getNodeMemories().getFirst();
} else {
// lia is in shared segment, so point to next node
bit = 2;
node = liaNode.getSinkPropagator().getFirstLeftTupleSink();
// skip the liaNode memory
nodeMem = smem.getNodeMemories().getFirst().getNext();
}
TupleSets<LeftTuple> srcTuples = smem.getStagedLeftTuples();
if (log.isTraceEnabled()) {
log.trace("Rule[name={}] segments={} {}", ((TerminalNode) pmem.getPathEndNode()).getRule().getName(), smems.length, srcTuples.toStringSizes());
}
outerEval(pmem, node, bit, nodeMem, smems, smemIndex, srcTuples, agenda, stack, true, executor);
}
use of org.drools.core.reteoo.TerminalNode in project drools by kiegroup.
the class AddRemoveRule method flushLeftTupleIfNecessary.
public static boolean flushLeftTupleIfNecessary(InternalWorkingMemory wm, SegmentMemory sm, LeftTuple leftTuple, boolean streamMode, short stagedType) {
PathMemory pmem = streamMode ? sm.getPathMemories().get(0) : sm.getFirstDataDrivenPathMemory();
if (pmem == null) {
return false;
}
TupleSets<LeftTuple> leftTupleSets = new TupleSetsImpl<LeftTuple>();
if (leftTuple != null) {
switch(stagedType) {
case Tuple.INSERT:
leftTupleSets.addInsert(leftTuple);
break;
case Tuple.DELETE:
leftTupleSets.addDelete(leftTuple);
break;
case Tuple.UPDATE:
leftTupleSets.addUpdate(leftTuple);
break;
}
}
forceFlushLeftTuple(pmem, sm, wm, leftTupleSets);
if (pmem.isDataDriven() && pmem.getNodeType() == NodeTypeEnums.RightInputAdaterNode) {
for (PathEndNode pnode : pmem.getPathEndNode().getPathEndNodes()) {
if (pnode instanceof TerminalNode) {
PathMemory outPmem = wm.getNodeMemory((TerminalNode) pnode);
if (outPmem.isDataDriven()) {
SegmentMemory outSmem = outPmem.getSegmentMemories()[0];
if (outSmem != null) {
forceFlushLeftTuple(outPmem, outSmem, wm, new TupleSetsImpl<LeftTuple>());
}
}
}
}
}
return true;
}
use of org.drools.core.reteoo.TerminalNode in project drools by kiegroup.
the class NodesPartitioningTest method checkNode.
private void checkNode(NetworkNode node) {
if (node instanceof EntryPointNode) {
assertSame(RuleBasePartitionId.MAIN_PARTITION, node.getPartitionId());
} else if (node instanceof ObjectTypeNode) {
assertSame(RuleBasePartitionId.MAIN_PARTITION, node.getPartitionId());
checkPartitionedSinks((ObjectTypeNode) node);
} else if (node instanceof ObjectSource) {
ObjectSource source = ((ObjectSource) node).getParentObjectSource();
if (!(source instanceof ObjectTypeNode)) {
assertSame(source.getPartitionId(), node.getPartitionId());
}
} else if (node instanceof BetaNode) {
ObjectSource rightInput = ((BetaNode) node).getRightInput();
if (!(rightInput instanceof ObjectTypeNode)) {
assertSame(rightInput.getPartitionId(), node.getPartitionId());
}
LeftTupleSource leftInput = ((BetaNode) node).getLeftTupleSource();
assertSame(leftInput.getPartitionId(), node.getPartitionId());
} else if (node instanceof TerminalNode) {
LeftTupleSource leftInput = ((TerminalNode) node).getLeftTupleSource();
assertSame(leftInput.getPartitionId(), node.getPartitionId());
}
}
use of org.drools.core.reteoo.TerminalNode in project drools by kiegroup.
the class TerminalNodeIteratorTest method testTerminalNodeListener.
@Test
public void testTerminalNodeListener() {
String str = "package org.kie.test \n" + "\n" + "rule rule1 when\n" + "then\n" + "end\n" + "rule rule2 when\n" + "then\n" + "end\n" + "rule rule3 when\n" + " Object()" + "then\n" + "end\n" + "rule rule4 when\n" + " Object()" + "then\n" + "end\n" + // this will result in two terminal nodes
"rule rule5 when\n" + " Object() or\n" + " Object()\n" + "then\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
List<String> nodes = new ArrayList<String>();
Iterator it = TerminalNodeIterator.iterator(kbase);
for (TerminalNode node = (TerminalNode) it.next(); node != null; node = (TerminalNode) it.next()) {
nodes.add(((RuleTerminalNode) node).getRule().getName());
}
assertEquals(6, nodes.size());
assertTrue(nodes.contains("rule1"));
assertTrue(nodes.contains("rule2"));
assertTrue(nodes.contains("rule3"));
assertTrue(nodes.contains("rule4"));
assertTrue(nodes.contains("rule5"));
int first = nodes.indexOf("rule5");
int second = nodes.lastIndexOf("rule5");
assertTrue(first != second);
}
use of org.drools.core.reteoo.TerminalNode in project drools by kiegroup.
the class NamedConsequenceBuilder method buildTerminalNodeForNamedConsequence.
static RuleTerminalNode buildTerminalNodeForNamedConsequence(BuildContext context, NamedConsequence namedConsequence) {
RuleImpl rule = context.getRule();
GroupElement subrule = (GroupElement) context.peek();
ActivationListenerFactory factory = context.getKnowledgeBase().getConfiguration().getActivationListenerFactory(rule.getActivationListener());
context.setConsequenceName(namedConsequence.getConsequenceName());
TerminalNode terminal = factory.createActivationListener(context.getNextId(), context.getTupleSource(), rule, subrule, // subruleIndex,
0, context);
context.setConsequenceName(null);
return (RuleTerminalNode) terminal;
}
Aggregations