use of org.drools.core.marshalling.TupleKey in project drools by kiegroup.
the class ProtobufInputMarshaller method readSession.
public static StatefulKnowledgeSessionImpl readSession(ProtobufMessages.KnowledgeSession _session, StatefulKnowledgeSessionImpl session, InternalAgenda agenda, ProtobufMarshallerReaderContext context) throws IOException, ClassNotFoundException {
GlobalResolver globalResolver = (GlobalResolver) context.env.get(EnvironmentName.GLOBALS);
if (globalResolver != null) {
session.setGlobalResolver(globalResolver);
}
if (session.getTimerService() instanceof PseudoClockScheduler) {
PseudoClockScheduler clock = (PseudoClockScheduler) session.getTimerService();
clock.advanceTime(_session.getTime(), TimeUnit.MILLISECONDS);
}
context.setWorkingMemory(session);
// need to read node memories before reading the fact handles
// because this data is required during fact propagation
readNodeMemories(context, _session.getRuleData());
List<PropagationContext> pctxs = new ArrayList<PropagationContext>();
if (_session.getRuleData().hasInitialFact()) {
session.setInitialFactHandle(session.initInitialFact(context));
context.getHandles().put(session.getInitialFactHandle().getId(), session.getInitialFactHandle());
}
for (ProtobufMessages.EntryPoint _ep : _session.getRuleData().getEntryPointList()) {
EntryPoint wmep = context.getWorkingMemory().getEntryPoint(_ep.getEntryPointId());
readFactHandles(context, _ep, ((WorkingMemoryEntryPoint) wmep).getObjectStore(), pctxs);
context.getWorkingMemory().getFactHandleFactory().doRecycleIds(context.getHandles().keySet());
context.getFilter().fireRNEAs(context.getWorkingMemory());
readTruthMaintenanceSystem(context, wmep, _ep, pctxs);
context.getWorkingMemory().getFactHandleFactory().stopRecycleIds();
}
cleanReaderContexts(pctxs);
readActionQueue(context, _session.getRuleData());
if (processMarshaller != null) {
if (_session.hasProcessData()) {
context.setParameterObject(_session.getProcessData());
processMarshaller.readProcessInstances(context);
context.setParameterObject(_session.getProcessData());
processMarshaller.readWorkItems(context);
// This actually does ALL timers, due to backwards compatability issues
// It will read in old JBPM binaries, but always write to the new binary format.
context.setParameterObject(_session.getProcessData());
processMarshaller.readProcessTimers(context);
}
} else {
if (_session.hasProcessData()) {
throw new IllegalStateException("No process marshaller, unable to unmarshall process data.");
}
}
if (_session.hasTimers()) {
for (ProtobufMessages.Timers.Timer _timer : _session.getTimers().getTimerList()) {
readTimer(context, _timer);
}
}
// need to process any eventual left over timer node timers
if (!context.timerNodeSchedulers.isEmpty()) {
for (Map<TupleKey, Scheduler> schedulers : context.timerNodeSchedulers.values()) {
for (Scheduler scheduler : schedulers.values()) {
scheduler.schedule(scheduler.getTrigger());
}
}
context.timerNodeSchedulers.clear();
}
// remove the activations filter
agenda.setActivationsFilter(null);
return session;
}
use of org.drools.core.marshalling.TupleKey in project drools by kiegroup.
the class ProtobufMarshallerReaderContext method createQueryResultHandle.
@Override
public QueryElementFactHandle createQueryResultHandle(Tuple leftTuple, Object[] objects, int nodeId) {
ProtobufMessages.FactHandle handle = null;
Map<TupleKey, ProtobufInputMarshaller.QueryElementContext> map = (Map<TupleKey, ProtobufInputMarshaller.QueryElementContext>) getNodeMemories().get(nodeId);
if (map != null) {
ProtobufInputMarshaller.QueryElementContext queryElementContext = map.get(TupleKey.createTupleKey(leftTuple));
if (queryElementContext != null) {
handle = queryElementContext.results.removeFirst();
}
}
return handle != null ? new QueryElementFactHandle(objects, handle.getId(), handle.getRecency()) : null;
}
use of org.drools.core.marshalling.TupleKey in project drools by kiegroup.
the class ProtobufMarshallerReaderContext method createAsyncNodeHandle.
@Override
public InternalFactHandle createAsyncNodeHandle(Tuple leftTuple, ReteEvaluator reteEvaluator, Object object, int nodeId, ObjectTypeConf objectTypeConf) {
ProtobufMessages.FactHandle _handle = null;
Map<TupleKey, List<ProtobufMessages.FactHandle>> map = (Map<TupleKey, List<ProtobufMessages.FactHandle>>) getNodeMemories().get(nodeId);
if (map != null) {
TupleKey key = TupleKey.createTupleKey(leftTuple);
List<ProtobufMessages.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<ProtobufMessages.FactHandle>) list).removeFirst();
if (list.isEmpty()) {
map.remove(key);
}
}
}
InternalFactHandle handle = null;
if (_handle != null) {
// create a handle with the given id
handle = reteEvaluator.getFactHandleFactory().newFactHandle(_handle.getId(), object, _handle.getRecency(), objectTypeConf, reteEvaluator, null);
}
return handle;
}
use of org.drools.core.marshalling.TupleKey in project drools by kiegroup.
the class ProtobufMarshallerReaderContext method createAccumulateHandle.
@Override
public InternalFactHandle createAccumulateHandle(EntryPointId entryPointId, ReteEvaluator reteEvaluator, LeftTuple leftTuple, Object result, int nodeId) {
InternalFactHandle handle = null;
ProtobufMessages.FactHandle _handle = null;
Map<TupleKey, ProtobufMessages.FactHandle> map = (Map<TupleKey, ProtobufMessages.FactHandle>) getNodeMemories().get(nodeId);
if (map != null) {
_handle = map.get(TupleKey.createTupleKey(leftTuple));
}
if (_handle != null) {
// create a handle with the given id
handle = reteEvaluator.getFactHandleFactory().newFactHandle(_handle.getId(), result, _handle.getRecency(), reteEvaluator.getDefaultEntryPoint().getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(entryPointId, result), reteEvaluator, // so far, result is not an event
null);
}
return handle;
}
use of org.drools.core.marshalling.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 ActivationsManager activationsManager, 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) {
ReteEvaluator reteEvaluator = activationsManager.getReteEvaluator();
if (leftTuple.getPropagationContext().getReaderContext() == null) {
final Trigger trigger = createTrigger(timerNode, reteEvaluator, timer, timestamp, calendarNames, calendars, leftTuple);
// regular propagation
scheduleTimer(timerNode, tm, smem, sink, reteEvaluator, 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, reteEvaluator, timerService, timestamp, leftTuple, trgLeftTuples, stagedLeftTuples, t);
evaluate(pmem, activationsManager, sink, tm, trgLeftTuples);
}
@Override
public Trigger getTrigger() {
return createTrigger(timerNode, reteEvaluator, timer, timestamp, calendarNames, calendars, leftTuple);
}
};
TupleKey key = TupleKey.createTupleKey(leftTuple);
leftTuple.getPropagationContext().getReaderContext().addTimerNodeScheduler(timerNode.getId(), key, scheduler);
leftTuple.setContextObject(key);
}
}
Aggregations