use of org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory in project drools by kiegroup.
the class PhreakQueryNode method doLeftUpdates.
public void doLeftUpdates(QueryElementNode queryNode, QueryElementNodeMemory qmem, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples) {
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
InternalFactHandle fh = (InternalFactHandle) leftTuple.getContextObject();
DroolsQuery dquery = (DroolsQuery) fh.getObject();
dquery.setParameters(queryNode.getActualArguments(leftTuple, wm));
SegmentMemory qsmem = qmem.getQuerySegmentMemory();
LeftInputAdapterNode lian = (LeftInputAdapterNode) qsmem.getRootNode();
LiaNodeMemory lmem = (LiaNodeMemory) qsmem.getNodeMemories().getFirst();
if (dquery.isOpen()) {
// there is only one, all other LTs are peers
LeftTuple childLeftTuple = fh.getFirstLeftTuple();
LeftInputAdapterNode.doUpdateObject(childLeftTuple, childLeftTuple.getPropagationContext(), wm, lian, false, lmem, qmem.getQuerySegmentMemory());
} else {
if (fh.getFirstLeftTuple() != null) {
// @TODO remove later (mdp)
throw new RuntimeException("defensive programming while testing");
}
LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
LeftInputAdapterNode.doInsertObject(fh, leftTuple.getPropagationContext(), lian, wm, lm, false, dquery.isOpen());
}
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory in project drools by kiegroup.
the class PhreakQueryNode method doLeftInserts.
public void doLeftInserts(QueryElementNode queryNode, QueryElementNodeMemory qmem, StackEntry stackEntry, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples) {
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext pCtx = leftTuple.getPropagationContext();
InternalFactHandle handle = queryNode.createFactHandle(pCtx, wm, leftTuple);
DroolsQuery dquery = queryNode.createDroolsQuery(leftTuple, handle, stackEntry, qmem.getSegmentMemory().getPathMemories(), qmem, stackEntry.getSink(), wm);
LeftInputAdapterNode lian = (LeftInputAdapterNode) qmem.getQuerySegmentMemory().getRootNode();
LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
LeftInputAdapterNode.doInsertObject(handle, pCtx, lian, wm, lm, false, dquery.isOpen());
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory in project drools by kiegroup.
the class SegmentUtilities method processLiaNode.
private static long processLiaNode(LeftInputAdapterNode tupleSource, InternalWorkingMemory wm, SegmentMemory smem, long nodePosMask, long allLinkedTestMask) {
LiaNodeMemory liaMemory = smem.createNodeMemory(tupleSource, wm);
liaMemory.setSegmentMemory(smem);
liaMemory.setNodePosMaskBit(nodePosMask);
allLinkedTestMask = allLinkedTestMask | nodePosMask;
return allLinkedTestMask;
}
use of org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory in project drools by kiegroup.
the class SegmentUtilities method getQuerySegmentMemory.
public static SegmentMemory getQuerySegmentMemory(InternalWorkingMemory wm, LeftTupleSource segmentRoot, QueryElementNode queryNode) {
LeftInputAdapterNode liaNode = getQueryLiaNode(queryNode.getQueryElement().getQueryName(), getQueryOtn(segmentRoot));
LiaNodeMemory liam = wm.getNodeMemory(liaNode);
SegmentMemory querySmem = liam.getSegmentMemory();
if (querySmem == null) {
querySmem = createSegmentMemory(liaNode, liam, wm);
}
return querySmem;
}
use of org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory in project drools by kiegroup.
the class SegmentCreationTest method testBranchCESingleSegment.
@Test
public void testBranchCESingleSegment() throws Exception {
KieBase kbase = buildKnowledgeBase(" $a : A() \n" + " if ( $a != null ) do[t1] \n" + " B() \n");
InternalWorkingMemory wm = ((InternalWorkingMemory) kbase.newKieSession());
ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class);
LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getObjectSinkPropagator().getSinks()[0];
ConditionalBranchNode cen1Node = (ConditionalBranchNode) liaNode.getSinkPropagator().getSinks()[0];
JoinNode bNode = (JoinNode) cen1Node.getSinkPropagator().getSinks()[0];
RuleTerminalNode rtn1 = (RuleTerminalNode) bNode.getSinkPropagator().getSinks()[0];
FactHandle bFh = wm.insert(new LinkingTest.B());
wm.flushPropagations();
LiaNodeMemory liaMem = (LiaNodeMemory) wm.getNodeMemory(liaNode);
SegmentMemory smem = liaMem.getSegmentMemory();
assertEquals(1, smem.getAllLinkedMaskTest());
// B links, but it will not trigger mask
assertEquals(4, smem.getLinkedNodeMask());
assertFalse(smem.isSegmentLinked());
PathMemory pmem = (PathMemory) wm.getNodeMemory(rtn1);
assertEquals(1, pmem.getAllLinkedMaskTest());
assertEquals(0, pmem.getLinkedSegmentMask());
assertFalse(pmem.isRuleLinked());
wm.insert(new LinkingTest.A());
wm.flushPropagations();
// A links in segment
assertEquals(5, smem.getLinkedNodeMask());
assertTrue(smem.isSegmentLinked());
assertEquals(1, pmem.getLinkedSegmentMask());
assertTrue(pmem.isRuleLinked());
// retract B does not unlink the rule
wm.delete(bFh);
wm.flushPropagations();
assertEquals(1, pmem.getLinkedSegmentMask());
assertTrue(pmem.isRuleLinked());
}
Aggregations