Search in sources :

Example 6 with TupleKey

use of org.drools.core.marshalling.TupleKey in project drools by kiegroup.

the class PhreakTimerNode method doLeftDeletes.

public void doLeftDeletes(TimerNode timerNode, TimerNodeMemory tm, PathMemory pmem, LeftTupleSink sink, ActivationsManager activationsManager, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
    TimerService timerService = activationsManager.getReteEvaluator().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.findMostRecentPropagationContext();
        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);
        }
        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(activationsManager);
                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.TupleKey) LeftTuple(org.drools.core.reteoo.LeftTuple) TimerService(org.drools.core.time.TimerService) DefaultJobHandle(org.drools.core.time.impl.DefaultJobHandle)

Example 7 with TupleKey

use of org.drools.core.marshalling.TupleKey in project drools by kiegroup.

the class TimerNodeTimerInputMarshaller method deserialize.

@Override
public void deserialize(MarshallerReaderContext inCtx, ProtobufMessages.Timers.Timer _timer) {
    ProtobufMessages.Timers.TimerNodeTimer _tn = _timer.getTimerNode();
    int timerNodeId = _tn.getNodeId();
    TupleKey tuple = PersisterHelper.createTupleKey(_tn.getTuple());
    Trigger trigger = ProtobufInputMarshaller.readTrigger(inCtx, _tn.getTrigger());
    PhreakTimerNode.Scheduler scheduler = inCtx.removeTimerNodeScheduler(timerNodeId, tuple);
    if (scheduler != null) {
        scheduler.schedule(trigger);
    }
}
Also used : PhreakTimerNode(org.drools.core.phreak.PhreakTimerNode) Trigger(org.drools.core.time.Trigger) TupleKey(org.drools.core.marshalling.TupleKey)

Aggregations

TupleKey (org.drools.core.marshalling.TupleKey)7 HashMap (java.util.HashMap)3 Map (java.util.Map)3 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)3 RightTupleKey (org.drools.serialization.protobuf.marshalling.RightTupleKey)3 InternalFactHandle (org.drools.core.common.InternalFactHandle)2 PropagationContext (org.drools.core.spi.PropagationContext)2 Trigger (org.drools.core.time.Trigger)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)1 ReteEvaluator (org.drools.core.common.ReteEvaluator)1 PhreakTimerNode (org.drools.core.phreak.PhreakTimerNode)1 Scheduler (org.drools.core.phreak.PhreakTimerNode.Scheduler)1 LeftTuple (org.drools.core.reteoo.LeftTuple)1 GlobalResolver (org.drools.core.spi.GlobalResolver)1 TimerService (org.drools.core.time.TimerService)1 DefaultJobHandle (org.drools.core.time.impl.DefaultJobHandle)1 PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)1 TupleList (org.drools.core.util.index.TupleList)1