use of org.drools.core.marshalling.impl.ProtobufInputMarshaller.TupleKey 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;
}
}
use of org.drools.core.marshalling.impl.ProtobufInputMarshaller.TupleKey in project drools by kiegroup.
the class PhreakTimerNode method scheduleLeftTuple.
private void scheduleLeftTuple(final TimerNode timerNode, final TimerNodeMemory tm, final PathMemory pmem, final SegmentMemory smem, final LeftTupleSink sink, final InternalAgenda agenda, final Timer timer, final TimerService timerService, final long timestamp, final String[] calendarNames, final Calendars calendars, final LeftTuple leftTuple, final TupleSets<LeftTuple> trgLeftTuples, final TupleSets<LeftTuple> stagedLeftTuples) {
InternalWorkingMemory wm = agenda.getWorkingMemory();
if (leftTuple.getPropagationContext().getReaderContext() == null) {
final Trigger trigger = createTrigger(timerNode, wm, timer, timestamp, calendarNames, calendars, leftTuple);
// regular propagation
scheduleTimer(timerNode, tm, smem, sink, wm, timerService, timestamp, leftTuple, trgLeftTuples, stagedLeftTuples, trigger);
} else {
// de-serializing, so we need to correlate timers before scheduling them
Scheduler scheduler = new Scheduler() {
@Override
public void schedule(Trigger t) {
scheduleTimer(timerNode, tm, smem, sink, wm, timerService, timestamp, leftTuple, trgLeftTuples, stagedLeftTuples, t);
evaluate(pmem, agenda, sink, tm, trgLeftTuples);
}
@Override
public Trigger getTrigger() {
return createTrigger(timerNode, wm, timer, timestamp, calendarNames, calendars, leftTuple);
}
};
TupleKey key = PersisterHelper.createTupleKey(leftTuple);
leftTuple.getPropagationContext().getReaderContext().addTimerNodeScheduler(timerNode.getId(), key, scheduler);
leftTuple.setContextObject(key);
}
}
use of org.drools.core.marshalling.impl.ProtobufInputMarshaller.TupleKey in project drools by kiegroup.
the class AccumulateNode method createResultFactHandle.
public InternalFactHandle createResultFactHandle(final PropagationContext context, final InternalWorkingMemory workingMemory, final LeftTuple leftTuple, final Object result) {
InternalFactHandle handle;
ProtobufMessages.FactHandle _handle = null;
if (context.getReaderContext() != null) {
Map<TupleKey, FactHandle> map = (Map<ProtobufInputMarshaller.TupleKey, ProtobufMessages.FactHandle>) context.getReaderContext().nodeMemories.get(getId());
if (map != null) {
_handle = map.get(PersisterHelper.createTupleKey(leftTuple));
}
}
if (_handle != null) {
// create a handle with the given id
handle = workingMemory.getFactHandleFactory().newFactHandle(_handle.getId(), result, _handle.getRecency(), workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf(context.getEntryPoint(), result), workingMemory, // so far, result is not an event
null);
} else {
handle = workingMemory.getFactHandleFactory().newFactHandle(result, workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf(context.getEntryPoint(), result), workingMemory, // so far, result is not an event
null);
}
return handle;
}
use of org.drools.core.marshalling.impl.ProtobufInputMarshaller.TupleKey in project drools by kiegroup.
the class FromNode method createFactHandle.
public InternalFactHandle createFactHandle(Tuple leftTuple, PropagationContext context, InternalWorkingMemory workingMemory, Object object) {
FactHandle _handle = null;
if (objectTypeConf == null) {
// use default entry point and object class. Notice that at this point object is assignable to resultClass
objectTypeConf = new ClassObjectTypeConf(workingMemory.getEntryPoint(), resultClass, workingMemory.getKnowledgeBase());
}
if (context.getReaderContext() != null) {
Map<TupleKey, List<FactHandle>> map = (Map<TupleKey, List<FactHandle>>) context.getReaderContext().nodeMemories.get(getId());
if (map != null) {
TupleKey key = PersisterHelper.createTupleKey(leftTuple);
List<FactHandle> list = map.get(key);
if (list != null && !list.isEmpty()) {
// it is a linked list, so the operation is fairly efficient
_handle = ((java.util.LinkedList<FactHandle>) list).removeFirst();
if (list.isEmpty()) {
map.remove(key);
}
}
}
}
InternalFactHandle handle;
if (_handle != null) {
// create a handle with the given id
handle = workingMemory.getFactHandleFactory().newFactHandle(_handle.getId(), object, _handle.getRecency(), objectTypeConf, workingMemory, null);
} else {
handle = workingMemory.getFactHandleFactory().newFactHandle(object, objectTypeConf, workingMemory, null);
}
return handle;
}
Aggregations