Search in sources :

Example 11 with LeftTuple

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

the class PhreakTimerNode method doLeftInserts.

public void doLeftInserts(TimerNode timerNode, TimerNodeMemory tm, PathMemory pmem, SegmentMemory smem, LeftTupleSink sink, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
    Timer timer = timerNode.getTimer();
    TimerService timerService = agenda.getWorkingMemory().getTimerService();
    long timestamp = timerService.getCurrentTime();
    String[] calendarNames = timerNode.getCalendarNames();
    Calendars calendars = agenda.getWorkingMemory().getCalendars();
    for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        scheduleLeftTuple(timerNode, tm, pmem, smem, sink, agenda, timer, timerService, timestamp, calendarNames, calendars, leftTuple, trgLeftTuples, null);
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : TimerNodeTimer(org.drools.core.marshalling.impl.ProtobufMessages.Timers.TimerNodeTimer) Timer(org.drools.core.time.impl.Timer) Calendars(org.kie.api.runtime.Calendars) LeftTuple(org.drools.core.reteoo.LeftTuple) TimerService(org.drools.core.time.TimerService)

Example 12 with LeftTuple

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

the class PhreakTimerNode method doPropagateChildLeftTuple.

private static LeftTuple doPropagateChildLeftTuple(LeftTupleSink sink, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples, LeftTuple leftTuple) {
    LeftTuple childLeftTuple = leftTuple.getFirstChild();
    if (childLeftTuple == null) {
        childLeftTuple = sink.createLeftTuple(leftTuple, sink, leftTuple.getPropagationContext(), true);
        trgLeftTuples.addInsert(childLeftTuple);
        if (log.isTraceEnabled()) {
            log.trace("Timer Insert {}", childLeftTuple);
        }
    } else if (childLeftTuple.getContextObject() == Boolean.TRUE) {
        // This childLeftTuple has been created in this doNode loop, just skip it
        childLeftTuple.setContextObject(null);
    } else {
        normalizeStagedTuples(stagedLeftTuples, childLeftTuple);
        trgLeftTuples.addUpdate(childLeftTuple);
        if (log.isTraceEnabled()) {
            log.trace("Timer Update {}", childLeftTuple);
        }
    }
    return childLeftTuple;
}
Also used : LeftTuple(org.drools.core.reteoo.LeftTuple)

Example 13 with LeftTuple

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

the class RuleNetworkEvaluator method doUpdatesReorderLeftMemory.

public static void doUpdatesReorderLeftMemory(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()) {
        ltm.remove(leftTuple);
    }
    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; leftTuple = leftTuple.getStagedNext()) {
        ltm.add(leftTuple);
        for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; ) {
            LeftTuple childNext = childLeftTuple.getHandleNext();
            childLeftTuple.reAddRight();
            childLeftTuple = childNext;
        }
    }
}
Also used : LeftTuple(org.drools.core.reteoo.LeftTuple) TupleMemory(org.drools.core.reteoo.TupleMemory)

Example 14 with LeftTuple

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

the class RuleNetworkEvaluator method doRiaNode.

private void doRiaNode(InternalAgenda agenda, PathMemory pmem, TupleSets<LeftTuple> srcTuples, BetaNode betaNode, LeftTupleSinkNode sink, SegmentMemory[] smems, int smemIndex, Memory nodeMem, BetaMemory bm, LinkedList<StackEntry> stack, RuleExecutor executor) {
    RiaPathMemory pathMem = bm.getRiaRuleMemory();
    SegmentMemory[] subnetworkSmems = pathMem.getSegmentMemories();
    SegmentMemory subSmem = null;
    for (int i = 0; subSmem == null; i++) {
        // segment positions outside of the subnetwork, in the parent chain, are null
        // so we must iterate to find the first non null segment memory
        subSmem = subnetworkSmems[i];
    }
    // Resume the node after the riaNode segment has been processed and the right input memory populated
    StackEntry stackEntry = new StackEntry(betaNode, bm.getNodePosMaskBit(), sink, pmem, nodeMem, smems, smemIndex, srcTuples, false, false);
    stack.add(stackEntry);
    if (log.isTraceEnabled()) {
        int offset = getOffset(betaNode);
        log.trace("{} RiaQueue {} {}", indent(offset), betaNode.toString(), srcTuples.toStringSizes());
    }
    TupleSets<LeftTuple> subLts = subSmem.getStagedLeftTuples().takeAll();
    // node is first in the segment, so bit is 1
    innerEval(pathMem, subSmem.getRootNode(), 1, subSmem.getNodeMemories().getFirst(), subnetworkSmems, subSmem.getPos(), subLts, agenda, stack, true, executor);
}
Also used : SegmentMemory(org.drools.core.reteoo.SegmentMemory) RiaPathMemory(org.drools.core.reteoo.RiaPathMemory) LeftTuple(org.drools.core.reteoo.LeftTuple)

Example 15 with LeftTuple

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

the class RuleNetworkEvaluator method doUpdatesReorderRightMemory.

public static void doUpdatesReorderRightMemory(BetaMemory bm, TupleSets<RightTuple> srcRightTuples) {
    TupleMemory rtm = bm.getRightTupleMemory();
    for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
        if (rightTuple.getMemory() != null) {
            rightTuple.setTempRightTupleMemory(rightTuple.getMemory());
            rtm.remove(rightTuple);
        }
    }
    for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
        if (rightTuple.getTempRightTupleMemory() != null) {
            rtm.add(rightTuple);
            for (LeftTuple childLeftTuple = rightTuple.getFirstChild(); childLeftTuple != null; ) {
                LeftTuple childNext = childLeftTuple.getRightParentNext();
                childLeftTuple.reAddLeft();
                childLeftTuple = childNext;
            }
        }
    }
}
Also used : RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) TupleMemory(org.drools.core.reteoo.TupleMemory)

Aggregations

LeftTuple (org.drools.core.reteoo.LeftTuple)125 RightTuple (org.drools.core.reteoo.RightTuple)41 TupleMemory (org.drools.core.reteoo.TupleMemory)37 InternalFactHandle (org.drools.core.common.InternalFactHandle)34 FastIterator (org.drools.core.util.FastIterator)22 BetaConstraints (org.drools.core.common.BetaConstraints)21 BetaMemory (org.drools.core.reteoo.BetaMemory)21 ContextEntry (org.drools.core.rule.ContextEntry)20 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)18 PhreakJoinNode.updateChildLeftTuple (org.drools.core.phreak.PhreakJoinNode.updateChildLeftTuple)16 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)13 SegmentMemory (org.drools.core.reteoo.SegmentMemory)13 Test (org.junit.Test)13 KieSession (org.kie.api.runtime.KieSession)13 Tuple (org.drools.core.spi.Tuple)12 WorkingMemory (org.drools.core.WorkingMemory)11 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)11 FromMemory (org.drools.core.reteoo.FromNode.FromMemory)10 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)9 ArrayList (java.util.ArrayList)8