Search in sources :

Example 1 with LiaNodeMemory

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;
    }
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) InternalFactHandle(org.drools.core.common.InternalFactHandle) LeftTuple(org.drools.core.reteoo.LeftTuple) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) DroolsQuery(org.drools.core.base.DroolsQuery) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 2 with LiaNodeMemory

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;
    }
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) InternalFactHandle(org.drools.core.common.InternalFactHandle) LeftTuple(org.drools.core.reteoo.LeftTuple) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) DroolsQuery(org.drools.core.base.DroolsQuery) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 3 with LiaNodeMemory

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;
}
Also used : LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)

Example 4 with LiaNodeMemory

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;
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 5 with LiaNodeMemory

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());
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) FactHandle(org.kie.api.runtime.rule.FactHandle) JoinNode(org.drools.core.reteoo.JoinNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) ConditionalBranchNode(org.drools.core.reteoo.ConditionalBranchNode) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) KieBase(org.kie.api.KieBase) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) RuleTerminalNode(org.drools.core.reteoo.RuleTerminalNode) PathMemory(org.drools.core.reteoo.PathMemory) Test(org.junit.Test)

Aggregations

LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)56 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)50 Test (org.junit.Test)46 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)42 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)42 SegmentMemory (org.drools.core.reteoo.SegmentMemory)36 JoinNode (org.drools.core.reteoo.JoinNode)29 ArrayList (java.util.ArrayList)22 BetaMemory (org.drools.core.reteoo.BetaMemory)22 List (java.util.List)21 KieBase (org.kie.api.KieBase)21 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)20 Match (org.kie.api.runtime.rule.Match)16 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)15 FactHandle (org.kie.api.runtime.rule.FactHandle)10 NotNode (org.drools.core.reteoo.NotNode)9 InternalFactHandle (org.drools.core.common.InternalFactHandle)8 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)8 Arrays.asList (java.util.Arrays.asList)7 RightInputAdapterNode (org.drools.core.reteoo.RightInputAdapterNode)7