Search in sources :

Example 31 with TupleMemory

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

the class RuleNetworkEvaluator method doUpdatesExistentialReorderRightMemory.

public static void doUpdatesExistentialReorderRightMemory(BetaMemory bm, BetaNode betaNode, TupleSets<RightTuple> srcRightTuples) {
    TupleMemory rtm = bm.getRightTupleMemory();
    boolean resumeFromCurrent = !(betaNode.isIndexedUnificationJoin() || rtm.getIndexType().isComparison());
    if (rtm.getIndexType() != TupleMemory.IndexType.NONE) {
        for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
            rtm.remove(rightTuple);
            if (rightTuple.getBlocked() != null) {
                rightTuple.removeBlocked(rightTuple.getBlocked());
            }
        }
    }
    for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
        doRemoveExistentialRightMemoryForReorder(rtm, resumeFromCurrent, rightTuple);
    }
    for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
        doAddExistentialRightMemoryForReorder(rtm, resumeFromCurrent, rightTuple);
    }
    if (rtm.getIndexType() != TupleMemory.IndexType.NONE) {
        for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
            rtm.add(rightTuple);
        }
    }
}
Also used : RightTuple(org.drools.core.reteoo.RightTuple) TupleMemory(org.drools.core.reteoo.TupleMemory)

Example 32 with TupleMemory

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

the class PhreakAccumulateNode method doRightUpdates.

public void doRightUpdates(AccumulateNode accNode, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
    BetaMemory bm = am.getBetaMemory();
    TupleMemory ltm = bm.getLeftTupleMemory();
    ContextEntry[] contextEntry = bm.getContext();
    BetaConstraints constraints = accNode.getRawConstraints();
    Accumulate accumulate = accNode.getAccumulate();
    for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; ) {
        RightTuple next = rightTuple.getStagedNext();
        if (ltm != null && ltm.size() > 0) {
            LeftTuple childLeftTuple = rightTuple.getFirstChild();
            FastIterator leftIt = accNode.getLeftIterator(ltm);
            LeftTuple leftTuple = accNode.getFirstLeftTuple(rightTuple, ltm, leftIt);
            constraints.updateFromFactHandle(contextEntry, wm, rightTuple.getFactHandleForEvaluation());
            // We assume a bucket change if leftTuple == null
            if (childLeftTuple != null && ltm.isIndexed() && !leftIt.isFullIterator() && (leftTuple == null || (leftTuple.getMemory() != childLeftTuple.getLeftParent().getMemory()))) {
                // our index has changed, so delete all the previous matches
                removePreviousMatchesForRightTuple(accNode, accumulate, rightTuple, wm, am, childLeftTuple, trgLeftTuples);
                // null so the next check will attempt matches for new bucket
                childLeftTuple = null;
            }
            // if LeftTupleMemory is empty, there are no matches to modify
            if (leftTuple != null) {
                if (leftTuple.getStagedType() == LeftTuple.NONE) {
                    trgLeftTuples.addUpdate(leftTuple);
                }
                doRightUpdatesProcessChildren(accNode, am, wm, bm, constraints, accumulate, leftIt, rightTuple, childLeftTuple, leftTuple, trgLeftTuples);
            }
        }
        rightTuple.clearStaged();
        rightTuple = next;
    }
    constraints.resetFactHandle(contextEntry);
}
Also used : BetaConstraints(org.drools.core.common.BetaConstraints) BetaMemory(org.drools.core.reteoo.BetaMemory) FastIterator(org.drools.core.util.FastIterator) RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) ContextEntry(org.drools.core.rule.ContextEntry) Accumulate(org.drools.core.rule.Accumulate)

Example 33 with TupleMemory

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

the class PhreakAccumulateNode method doRightDeletes.

public void doRightDeletes(AccumulateNode accNode, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
    TupleMemory rtm = am.getBetaMemory().getRightTupleMemory();
    Accumulate accumulate = accNode.getAccumulate();
    for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; ) {
        RightTuple next = rightTuple.getStagedNext();
        if (rightTuple.getMemory() != null) {
            // it may have been staged and never actually added
            rtm.remove(rightTuple);
            if (rightTuple.getFirstChild() != null) {
                LeftTuple match = rightTuple.getFirstChild();
                while (match != null) {
                    LeftTuple nextLeft = match.getRightParentNext();
                    LeftTuple leftTuple = match.getLeftParent();
                    final AccumulateContext accctx = (AccumulateContext) leftTuple.getContextObject();
                    removeMatch(accNode, accumulate, rightTuple, match, wm, am, accctx, true);
                    if (leftTuple.getStagedType() == LeftTuple.NONE) {
                        trgLeftTuples.addUpdate(leftTuple);
                    }
                    match = nextLeft;
                }
            }
        }
        rightTuple.clearStaged();
        rightTuple = next;
    }
}
Also used : RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) AccumulateContext(org.drools.core.reteoo.AccumulateNode.AccumulateContext) Accumulate(org.drools.core.rule.Accumulate)

Example 34 with TupleMemory

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

the class PhreakJoinNode method doLeftInserts.

public void doLeftInserts(JoinNode joinNode, LeftTupleSink sink, BetaMemory bm, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
    TupleMemory ltm = bm.getLeftTupleMemory();
    TupleMemory rtm = bm.getRightTupleMemory();
    ContextEntry[] contextEntry = bm.getContext();
    BetaConstraints constraints = joinNode.getRawConstraints();
    for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        boolean useLeftMemory = RuleNetworkEvaluator.useLeftMemory(joinNode, leftTuple);
        if (useLeftMemory) {
            ltm.add(leftTuple);
        }
        FastIterator it = joinNode.getRightIterator(rtm);
        constraints.updateFromTuple(contextEntry, wm, leftTuple);
        for (RightTuple rightTuple = joinNode.getFirstRightTuple(leftTuple, rtm, null, it); rightTuple != null; rightTuple = (RightTuple) it.next(rightTuple)) {
            if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandle())) {
                insertChildLeftTuple(trgLeftTuples, leftTuple, rightTuple, null, null, sink, useLeftMemory);
            }
        }
        leftTuple.clearStaged();
        leftTuple = next;
    }
    constraints.resetTuple(contextEntry);
}
Also used : BetaConstraints(org.drools.core.common.BetaConstraints) FastIterator(org.drools.core.util.FastIterator) LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) ContextEntry(org.drools.core.rule.ContextEntry)

Example 35 with TupleMemory

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

the class PhreakJoinNode method doRightInserts.

public void doRightInserts(JoinNode joinNode, LeftTupleSink sink, BetaMemory bm, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
    TupleMemory ltm = bm.getLeftTupleMemory();
    TupleMemory rtm = bm.getRightTupleMemory();
    ContextEntry[] contextEntry = bm.getContext();
    BetaConstraints constraints = joinNode.getRawConstraints();
    if (srcRightTuples.getInsertSize() > 32 && rtm instanceof AbstractHashTable) {
        ((AbstractHashTable) rtm).ensureCapacity(srcRightTuples.getInsertSize());
    }
    for (RightTuple rightTuple = srcRightTuples.getInsertFirst(); rightTuple != null; ) {
        RightTuple next = rightTuple.getStagedNext();
        rtm.add(rightTuple);
        if (ltm != null && ltm.size() > 0) {
            FastIterator it = joinNode.getLeftIterator(ltm);
            constraints.updateFromFactHandle(contextEntry, wm, rightTuple.getFactHandleForEvaluation());
            for (LeftTuple leftTuple = joinNode.getFirstLeftTuple(rightTuple, ltm, it); leftTuple != null; leftTuple = (LeftTuple) it.next(leftTuple)) {
                if (leftTuple.getStagedType() == LeftTuple.UPDATE) {
                    // ignore, as it will get processed via left iteration. Children cannot be processed twice
                    continue;
                }
                if (constraints.isAllowedCachedRight(contextEntry, leftTuple)) {
                    insertChildLeftTuple(trgLeftTuples, leftTuple, rightTuple, null, null, sink, true);
                }
            }
        }
        rightTuple.clearStaged();
        rightTuple = next;
    }
    constraints.resetFactHandle(contextEntry);
}
Also used : AbstractHashTable(org.drools.core.util.AbstractHashTable) BetaConstraints(org.drools.core.common.BetaConstraints) FastIterator(org.drools.core.util.FastIterator) RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) ContextEntry(org.drools.core.rule.ContextEntry)

Aggregations

TupleMemory (org.drools.core.reteoo.TupleMemory)66 LeftTuple (org.drools.core.reteoo.LeftTuple)59 RightTuple (org.drools.core.reteoo.RightTuple)52 FastIterator (org.drools.core.util.FastIterator)40 BetaConstraints (org.drools.core.common.BetaConstraints)36 ContextEntry (org.drools.core.rule.ContextEntry)36 PhreakJoinNode.updateChildLeftTuple (org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple)23 BetaMemory (org.drools.core.reteoo.BetaMemory)23 Accumulate (org.drools.core.rule.Accumulate)12 Tuple (org.drools.core.spi.Tuple)9 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)8 ArrayList (java.util.ArrayList)6 BetaNode (org.drools.core.reteoo.BetaNode)6 InternalFactHandle (org.drools.core.common.InternalFactHandle)5 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)5 BaseAccumulation (org.drools.core.reteoo.AccumulateNode.BaseAccumulation)5 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)5 PhreakPropagationContext (org.drools.core.common.PhreakPropagationContext)4 AccumulateContextEntry (org.drools.core.reteoo.AccumulateNode.AccumulateContextEntry)4 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)4