Search in sources :

Example 6 with LeftTuple

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

the class PhreakRuleTerminalNode method doLeftInserts.

public void doLeftInserts(TerminalNode rtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, RuleExecutor executor) {
    RuleAgendaItem ruleAgendaItem = executor.getRuleAgendaItem();
    int salienceInt = 0;
    Salience salience = ruleAgendaItem.getRule().getSalience();
    if (!salience.isDynamic()) {
        salienceInt = salience.getValue();
        salience = null;
    }
    if (rtnNode.getRule().getAutoFocus() && !ruleAgendaItem.getAgendaGroup().isActive()) {
        agenda.setFocus(ruleAgendaItem.getAgendaGroup());
    }
    for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        doLeftTupleInsert(rtnNode, executor, agenda, ruleAgendaItem, salienceInt, salience, leftTuple);
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : Salience(org.drools.core.spi.Salience) LeftTuple(org.drools.core.reteoo.LeftTuple) RuleTerminalNodeLeftTuple(org.drools.core.reteoo.RuleTerminalNodeLeftTuple)

Example 7 with LeftTuple

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

the class PhreakRuleTerminalNode method doLeftUpdates.

public void doLeftUpdates(TerminalNode rtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, RuleExecutor executor) {
    RuleAgendaItem ruleAgendaItem = executor.getRuleAgendaItem();
    if (rtnNode.getRule().getAutoFocus() && !ruleAgendaItem.getAgendaGroup().isActive()) {
        agenda.setFocus(ruleAgendaItem.getAgendaGroup());
    }
    int salienceInt = 0;
    Salience salience = ruleAgendaItem.getRule().getSalience();
    if (!salience.isDynamic()) {
        salienceInt = salience.getValue();
        salience = null;
    }
    // Salience salienceInt = ruleAgendaItem.getRule().getSalience();
    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        doLeftTupleUpdate(rtnNode, executor, agenda, salienceInt, salience, leftTuple);
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : Salience(org.drools.core.spi.Salience) LeftTuple(org.drools.core.reteoo.LeftTuple) RuleTerminalNodeLeftTuple(org.drools.core.reteoo.RuleTerminalNodeLeftTuple)

Example 8 with LeftTuple

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

the class PhreakTimerNode method doLeftDeletes.

public void doLeftDeletes(TimerNode timerNode, TimerNodeMemory tm, PathMemory pmem, LeftTupleSink sink, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
    TimerService timerService = agenda.getWorkingMemory().getTimerService();
    TupleList leftTuples = tm.getInsertOrUpdateLeftTuples();
    TupleList deletes = tm.getDeleteLeftTuples();
    if (!deletes.isEmpty()) {
        for (LeftTuple leftTuple = (LeftTuple) deletes.getFirst(); leftTuple != null; ) {
            LeftTuple next = (LeftTuple) leftTuple.getNext();
            srcLeftTuples.addDelete(leftTuple);
            if (log.isTraceEnabled()) {
                log.trace("Timer Add Postponed Delete {}", leftTuple);
            }
            leftTuple.clear();
            leftTuple = next;
        }
        deletes.clear();
    }
    for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        PropagationContext pctx = leftTuple.getPropagationContext();
        Object obj = leftTuple.getContextObject();
        if (obj instanceof DefaultJobHandle) {
            timerService.removeJob((DefaultJobHandle) obj);
        } else if (obj instanceof TupleKey && pctx.getReaderContext() != null) {
            pctx.getReaderContext().removeTimerNodeScheduler(timerNode.getId(), (TupleKey) obj);
        }
        pctx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, pctx);
        if (leftTuple.getMemory() != null) {
            // it gets removed either way.
            leftTuples.remove(leftTuple);
            if (pctx.getFactHandle().isExpired()) {
                // a expire clashes with insert or update, allow it to propagate once, will handle the expire the second time around
                doPropagateChildLeftTuple(sink, trgLeftTuples, stagedLeftTuples, leftTuple);
                tm.getDeleteLeftTuples().add(leftTuple);
                // make sure it's dirty, so it'll evaluate again
                pmem.doLinkRule(agenda);
                if (log.isTraceEnabled()) {
                    log.trace("Timer Postponed Delete {}", leftTuple);
                }
            }
        }
        if (leftTuple.getMemory() == null) {
            // if it's != null, then it's already been postponed, and the existing child propagated
            // only has one child
            LeftTuple childLeftTuple = leftTuple.getFirstChild();
            if (childLeftTuple != null) {
                childLeftTuple.setPropagationContext(leftTuple.getPropagationContext());
                RuleNetworkEvaluator.deleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
                if (log.isTraceEnabled()) {
                    log.trace("Timer Delete {}", leftTuple);
                }
            }
        }
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : TupleList(org.drools.core.util.index.TupleList) PropagationContext(org.drools.core.spi.PropagationContext) TupleKey(org.drools.core.marshalling.impl.ProtobufInputMarshaller.TupleKey) LeftTuple(org.drools.core.reteoo.LeftTuple) TimerService(org.drools.core.time.TimerService) DefaultJobHandle(org.drools.core.time.impl.DefaultJobHandle)

Example 9 with LeftTuple

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

the class PhreakTimerNode method doPropagateChildLeftTuples.

private static void doPropagateChildLeftTuples(TimerNodeMemory tm, LeftTupleSink sink, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
    TupleList leftTuples = tm.getInsertOrUpdateLeftTuples();
    for (LeftTuple leftTuple = (LeftTuple) leftTuples.getFirst(); leftTuple != null; ) {
        LeftTuple next = (LeftTuple) leftTuple.getNext();
        doPropagateChildLeftTuple(sink, trgLeftTuples, stagedLeftTuples, leftTuple);
        leftTuple.clear();
        leftTuple = next;
    }
    // doLeftDeletes handles deletes, directly into the trgLeftTuples
    if (tm.getDeleteLeftTuples().isEmpty()) {
        // dirty bit can only be reset when there are no InsertOUdate LeftTuples and no Delete staged LeftTuples.
        tm.setNodeCleanWithoutNotify();
    }
    leftTuples.clear();
}
Also used : TupleList(org.drools.core.util.index.TupleList) LeftTuple(org.drools.core.reteoo.LeftTuple)

Example 10 with LeftTuple

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

the class PhreakTimerNode method doLeftUpdates.

public void doLeftUpdates(TimerNode timerNode, TimerNodeMemory tm, PathMemory pmem, SegmentMemory smem, LeftTupleSink sink, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
    Timer timer = timerNode.getTimer();
    // Variables may have changed for ExpressionIntervalTimer, so it must be rescheduled
    TimerService timerService = agenda.getWorkingMemory().getTimerService();
    long timestamp = timerService.getCurrentTime();
    String[] calendarNames = timerNode.getCalendarNames();
    Calendars calendars = agenda.getWorkingMemory().getCalendars();
    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        DefaultJobHandle jobHandle = (DefaultJobHandle) leftTuple.getContextObject();
        if (jobHandle != null) {
            // jobHandle can be null, if the time fired straight away, and never ended up scheduling a job
            timerService.removeJob(jobHandle);
        }
        scheduleLeftTuple(timerNode, tm, pmem, smem, sink, agenda, timer, timerService, timestamp, calendarNames, calendars, leftTuple, trgLeftTuples, stagedLeftTuples);
        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) DefaultJobHandle(org.drools.core.time.impl.DefaultJobHandle)

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