Search in sources :

Example 6 with SegmentMemory

use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.

the class SegmentPropagator method processPeers.

private static void processPeers(SegmentMemory sourceSegment, TupleSets<LeftTuple> leftTuples, InternalWorkingMemory wm) {
    SegmentMemory firstSmem = sourceSegment.getFirst();
    // Process Deletes
    processPeerDeletes(leftTuples, leftTuples.getDeleteFirst(), firstSmem, wm);
    processPeerDeletes(leftTuples, leftTuples.getNormalizedDeleteFirst(), firstSmem, wm);
    // Process Updates
    for (LeftTuple leftTuple = leftTuples.getUpdateFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
        SegmentMemory smem = firstSmem.getNext();
        if (smem != null) {
            for (LeftTuple peer = leftTuple.getPeer(); peer != null; peer = peer.getPeer()) {
                // only stage, if not already staged, if insert, leave as insert
                if (peer.getStagedType() == LeftTuple.NONE) {
                    peer.setPropagationContext(leftTuple.getPropagationContext());
                    smem.getStagedLeftTuples().addUpdate(peer);
                }
                smem = smem.getNext();
            }
        }
    }
    // Process Inserts
    for (LeftTuple leftTuple = leftTuples.getInsertFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
        SegmentMemory smem = firstSmem.getNext();
        if (smem != null) {
            LeftTuple peer = leftTuple;
            for (; smem != null; smem = smem.getNext()) {
                if (peer.getPeer() != null) {
                    // if the tuple already has a peer avoid to create a new one ...
                    peer = peer.getPeer();
                    peer.setPropagationContext(leftTuple.getPropagationContext());
                    // ... and update the staged LeftTupleSets according to its current staged state
                    PhreakJoinNode.updateChildLeftTuple(peer, smem.getStagedLeftTuples(), smem.getStagedLeftTuples());
                } else {
                    peer = ((LeftTupleSink) smem.getRootNode()).createPeer(peer);
                    smem.getStagedLeftTuples().addInsert(peer);
                    if (smem.hasDataDrivenPathMemories()) {
                        for (PathMemory dataDrivenPmem : smem.getDataDrivenPathMemories()) {
                            // on insert only totally linked pmems need to be flushed
                            if (dataDrivenPmem.isRuleLinked()) {
                                forceFlushLeftTuple(dataDrivenPmem, smem, wm, smem.getStagedLeftTuples());
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    firstSmem.getStagedLeftTuples().addAll(leftTuples);
    leftTuples.resetAll();
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) AddRemoveRule.forceFlushLeftTuple(org.drools.core.phreak.AddRemoveRule.forceFlushLeftTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) PathMemory(org.drools.core.reteoo.PathMemory)

Example 7 with SegmentMemory

use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.

the class SegmentPropagator method processPeerDeletes.

private static void processPeerDeletes(TupleSets<LeftTuple> leftTuples, LeftTuple leftTuple, SegmentMemory firstSmem, InternalWorkingMemory wm) {
    for (; leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
        SegmentMemory smem = firstSmem.getNext();
        if (smem != null) {
            for (LeftTuple peer = leftTuple.getPeer(); peer != null; peer = peer.getPeer()) {
                peer.setPropagationContext(leftTuple.getPropagationContext());
                TupleSets<LeftTuple> stagedLeftTuples = smem.getStagedLeftTuples();
                // if the peer is already staged as insert or update the LeftTupleSets will reconcile it internally
                stagedLeftTuples.addDelete(peer);
                if (smem.hasDataDrivenPathMemories()) {
                    forceFlushLeftTuple(smem.getFirstDataDrivenPathMemory(), smem, wm, smem.getStagedLeftTuples());
                }
                smem = smem.getNext();
            }
        }
    }
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) AddRemoveRule.forceFlushLeftTuple(org.drools.core.phreak.AddRemoveRule.forceFlushLeftTuple) LeftTuple(org.drools.core.reteoo.LeftTuple)

Example 8 with SegmentMemory

use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.

the class SegmentUtilities method createRiaSegmentMemory.

private static RightInputAdapterNode createRiaSegmentMemory(BetaNode betaNode, InternalWorkingMemory wm) {
    RightInputAdapterNode riaNode = (RightInputAdapterNode) betaNode.getRightInput();
    LeftTupleSource subnetworkLts = riaNode.getLeftTupleSource();
    while (subnetworkLts.getLeftTupleSource() != riaNode.getStartTupleSource()) {
        subnetworkLts = subnetworkLts.getLeftTupleSource();
    }
    Memory rootSubNetwokrMem = wm.getNodeMemory((MemoryFactory) subnetworkLts);
    SegmentMemory subNetworkSegmentMemory = rootSubNetwokrMem.getSegmentMemory();
    if (subNetworkSegmentMemory == null) {
        // we need to stop recursion here
        createSegmentMemory(subnetworkLts, rootSubNetwokrMem, wm);
    }
    return riaNode;
}
Also used : LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) SegmentMemory(org.drools.core.reteoo.SegmentMemory) Memory(org.drools.core.common.Memory) TimerNodeMemory(org.drools.core.reteoo.TimerNode.TimerNodeMemory) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) BetaMemory(org.drools.core.reteoo.BetaMemory) EvalMemory(org.drools.core.reteoo.EvalConditionNode.EvalMemory) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory) SegmentMemory(org.drools.core.reteoo.SegmentMemory) PathMemory(org.drools.core.reteoo.PathMemory) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ConditionalBranchMemory(org.drools.core.reteoo.ConditionalBranchNode.ConditionalBranchMemory) RiaNodeMemory(org.drools.core.reteoo.RightInputAdapterNode.RiaNodeMemory) AccumulateMemory(org.drools.core.reteoo.AccumulateNode.AccumulateMemory) RightInputAdapterNode(org.drools.core.reteoo.RightInputAdapterNode)

Example 9 with SegmentMemory

use of org.drools.core.reteoo.SegmentMemory in project drools by kiegroup.

the class SegmentUtilities method processQueryNode.

private static boolean processQueryNode(QueryElementNode queryNode, InternalWorkingMemory wm, LeftTupleSource segmentRoot, SegmentMemory smem, long nodePosMask) {
    // Initialize the QueryElementNode and have it's memory reference the actual query SegmentMemory
    SegmentMemory querySmem = getQuerySegmentMemory(wm, segmentRoot, queryNode);
    QueryElementNodeMemory queryNodeMem = smem.createNodeMemory(queryNode, wm);
    queryNodeMem.setNodePosMaskBit(nodePosMask);
    queryNodeMem.setQuerySegmentMemory(querySmem);
    queryNodeMem.setSegmentMemory(smem);
    return !queryNode.getQueryElement().isAbductive();
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) QueryElementNodeMemory(org.drools.core.reteoo.QueryElementNode.QueryElementNodeMemory)

Example 10 with SegmentMemory

use of org.drools.core.reteoo.SegmentMemory 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)

Aggregations

SegmentMemory (org.drools.core.reteoo.SegmentMemory)67 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)43 PathMemory (org.drools.core.reteoo.PathMemory)30 Test (org.junit.Test)30 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)27 BetaMemory (org.drools.core.reteoo.BetaMemory)23 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)23 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)22 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)18 JoinNode (org.drools.core.reteoo.JoinNode)18 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)18 ArrayList (java.util.ArrayList)16 List (java.util.List)15 Memory (org.drools.core.common.Memory)14 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)12 LeftTuple (org.drools.core.reteoo.LeftTuple)12 Match (org.kie.api.runtime.rule.Match)11 RiaNodeMemory (org.drools.core.reteoo.RightInputAdapterNode.RiaNodeMemory)10 KieBase (org.kie.api.KieBase)10 Arrays.asList (java.util.Arrays.asList)9