Search in sources :

Example 21 with ContextEntry

use of org.drools.core.rule.ContextEntry in project drools by kiegroup.

the class PhreakNotNode method doRightInserts.

public void doRightInserts(NotNode notNode, BetaMemory bm, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
    TupleMemory ltm = bm.getLeftTupleMemory();
    TupleMemory rtm = bm.getRightTupleMemory();
    ContextEntry[] contextEntry = bm.getContext();
    BetaConstraints constraints = notNode.getRawConstraints();
    // this must be processed here, rather than initial insert, as we need to link the blocker
    unlinkNotNodeOnRightInsert(notNode, bm, wm);
    for (RightTuple rightTuple = srcRightTuples.getInsertFirst(); rightTuple != null; ) {
        RightTuple next = rightTuple.getStagedNext();
        rtm.add(rightTuple);
        if (ltm != null && ltm.size() > 0) {
            FastIterator it = notNode.getLeftIterator(ltm);
            constraints.updateFromFactHandle(contextEntry, wm, rightTuple.getFactHandleForEvaluation());
            for (LeftTuple leftTuple = notNode.getFirstLeftTuple(rightTuple, ltm, it); leftTuple != null; ) {
                // preserve next now, in case we remove this leftTuple
                LeftTuple temp = (LeftTuple) it.next(leftTuple);
                if (leftTuple.getStagedType() == LeftTuple.UPDATE) {
                    // ignore, as it will get processed via left iteration. Children cannot be processed twice
                    leftTuple = temp;
                    continue;
                }
                // we know that only unblocked LeftTuples are  still in the memory
                if (constraints.isAllowedCachedRight(contextEntry, leftTuple)) {
                    leftTuple.setBlocker(rightTuple);
                    rightTuple.addBlocked(leftTuple);
                    // this is now blocked so remove from memory
                    ltm.remove(leftTuple);
                    // subclasses like ForallNotNode might override this propagation
                    // ** @TODO (mdp) need to not break forall
                    LeftTuple childLeftTuple = leftTuple.getFirstChild();
                    if (childLeftTuple != null) {
                        // NotNode only has one child
                        childLeftTuple.setPropagationContext(rightTuple.getPropagationContext());
                        RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
                    }
                }
                leftTuple = temp;
            }
        }
        rightTuple.clearStaged();
        rightTuple = next;
    }
    constraints.resetFactHandle(contextEntry);
}
Also used : BetaConstraints(org.drools.core.common.BetaConstraints) FastIterator(org.drools.core.util.FastIterator) RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) PhreakJoinNode.updateChildLeftTuple(org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) ContextEntry(org.drools.core.rule.ContextEntry)

Aggregations

BetaConstraints (org.drools.core.common.BetaConstraints)21 ContextEntry (org.drools.core.rule.ContextEntry)21 LeftTuple (org.drools.core.reteoo.LeftTuple)20 RightTuple (org.drools.core.reteoo.RightTuple)18 TupleMemory (org.drools.core.reteoo.TupleMemory)18 FastIterator (org.drools.core.util.FastIterator)18 PhreakJoinNode.updateChildLeftTuple (org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple)12 BetaMemory (org.drools.core.reteoo.BetaMemory)6 Accumulate (org.drools.core.rule.Accumulate)4 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)3 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)2 DataProvider (org.drools.core.spi.DataProvider)2 PropagationContext (org.drools.core.spi.PropagationContext)2 AbstractHashTable (org.drools.core.util.AbstractHashTable)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)1