Search in sources :

Example 56 with RightTuple

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

the class RuleNetworkEvaluator method doUpdatesExistentialReorderLeftMemory.

public static void doUpdatesExistentialReorderLeftMemory(BetaMemory bm, TupleSets<LeftTuple> srcLeftTuples) {
    TupleMemory ltm = bm.getLeftTupleMemory();
    // sides must first be re-ordered, to ensure iteration integrity
    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
        if (leftTuple.getMemory() != null) {
            ltm.remove(leftTuple);
        }
    }
    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
        RightTuple blocker = leftTuple.getBlocker();
        if (blocker == null) {
            ltm.add(leftTuple);
            for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; ) {
                LeftTuple childNext = childLeftTuple.getHandleNext();
                childLeftTuple.reAddRight();
                childLeftTuple = childNext;
            }
        } else if (blocker.getStagedType() != LeftTuple.NONE) {
            // it's blocker is also being updated, so remove to force it to start from the beginning
            blocker.removeBlocked(leftTuple);
        }
    }
}
Also used : LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) TupleMemory(org.drools.core.reteoo.TupleMemory)

Example 57 with RightTuple

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

the class RightMemory method getRightTuples.

public List<RightTuple> getRightTuples(Object... objects) {
    BetaNode node = scenario.getBetaNode();
    BetaMemory bm = scenario.getBm();
    TupleMemory rtm = bm.getRightTupleMemory();
    InternalWorkingMemory wm = scenario.getWorkingMemory();
    if (objects == null) {
        objects = new Object[0];
    }
    List<RightTuple> rightTuples = new ArrayList<RightTuple>();
    for (Object object : objects) {
        InternalFactHandle fh = (InternalFactHandle) wm.insert(object);
        // node.createLeftTuple( fh, node, true );
        RightTuple expectedRightTuple = new RightTupleImpl(fh, node);
        expectedRightTuple.setPropagationContext(new PhreakPropagationContext());
        rightTuples.add(expectedRightTuple);
    }
    scenario.setTestRightMemory(true);
    return rightTuples;
}
Also used : InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) PhreakPropagationContext(org.drools.core.common.PhreakPropagationContext) BetaNode(org.drools.core.reteoo.BetaNode) ArrayList(java.util.ArrayList) BetaMemory(org.drools.core.reteoo.BetaMemory) RightTupleImpl(org.drools.core.reteoo.RightTupleImpl) InternalFactHandle(org.drools.core.common.InternalFactHandle) RightTuple(org.drools.core.reteoo.RightTuple) TupleMemory(org.drools.core.reteoo.TupleMemory)

Example 58 with RightTuple

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

the class RightBuilder method delete.

public RightBuilder delete(Object... objects) {
    for (Object object : objects) {
        InternalFactHandle fh = (InternalFactHandle) wm.insert(object);
        RightTuple rightTuple = fh.getFirstRightTuple();
        rightTuple.setPropagationContext(new PhreakPropagationContext());
        rightTuples.addDelete(rightTuple);
    }
    return this;
}
Also used : PhreakPropagationContext(org.drools.core.common.PhreakPropagationContext) InternalFactHandle(org.drools.core.common.InternalFactHandle) RightTuple(org.drools.core.reteoo.RightTuple)

Example 59 with RightTuple

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

the class RightBuilder method insert.

public RightBuilder insert(Object... objects) {
    for (Object object : objects) {
        InternalFactHandle fh = (InternalFactHandle) wm.insert(object);
        RightTuple rightTuple = new RightTupleImpl(fh, sink);
        rightTuple.setPropagationContext(new PhreakPropagationContext());
        rightTuples.addInsert(rightTuple);
    }
    return this;
}
Also used : PhreakPropagationContext(org.drools.core.common.PhreakPropagationContext) RightTupleImpl(org.drools.core.reteoo.RightTupleImpl) InternalFactHandle(org.drools.core.common.InternalFactHandle) RightTuple(org.drools.core.reteoo.RightTuple)

Example 60 with RightTuple

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

the class Scenario method equalsRightMemory.

public void equalsRightMemory(List<RightTuple> rightTuples) {
    TupleMemory rtm = bm.getRightTupleMemory();
    int length = 0;
    for (RightTuple expectedRightTuple : rightTuples) {
        FastIterator it = betaNode.getRightIterator(rtm);
        Tuple actualRightTuple = null;
        for (actualRightTuple = BetaNode.getFirstTuple(rtm, it); actualRightTuple != null; actualRightTuple = (RightTuple) it.next(actualRightTuple)) {
            if (expectedRightTuple.equals(actualRightTuple)) {
                length++;
                break;
            }
        }
        if (actualRightTuple == null) {
            fail("Could not find RightTuple: " + expectedRightTuple);
        }
    }
    if (rightTuples.size() != rtm.size()) {
        fail("RightTuple memory size did not match: " + length);
    }
}
Also used : FastIterator(org.drools.core.util.FastIterator) RightTuple(org.drools.core.reteoo.RightTuple) TupleMemory(org.drools.core.reteoo.TupleMemory) LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) Tuple(org.drools.core.spi.Tuple)

Aggregations

RightTuple (org.drools.core.reteoo.RightTuple)60 LeftTuple (org.drools.core.reteoo.LeftTuple)41 TupleMemory (org.drools.core.reteoo.TupleMemory)30 FastIterator (org.drools.core.util.FastIterator)26 InternalFactHandle (org.drools.core.common.InternalFactHandle)20 BetaMemory (org.drools.core.reteoo.BetaMemory)20 BetaConstraints (org.drools.core.common.BetaConstraints)19 ContextEntry (org.drools.core.rule.ContextEntry)18 PhreakJoinNode.updateChildLeftTuple (org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple)13 Test (org.junit.Test)13 Tuple (org.drools.core.spi.Tuple)11 RightTupleImpl (org.drools.core.reteoo.RightTupleImpl)10 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)9 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)8 BetaNode (org.drools.core.reteoo.BetaNode)7 FromMemory (org.drools.core.reteoo.FromNode.FromMemory)7 ArrayList (java.util.ArrayList)6 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)6 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)6 Accumulate (org.drools.core.rule.Accumulate)6