use of org.drools.core.WorkingMemoryEntryPoint 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.WorkingMemoryEntryPoint in project drools by kiegroup.
the class EventListDataStream method insertAndAdvanceClock.
private void insertAndAdvanceClock(T t, DataProcessor subscriber) {
EventFactHandle fh = (EventFactHandle) subscriber.insert(null, t);
long timestamp = fh.getStartTimestamp();
WorkingMemoryEntryPoint ep = fh.getEntryPoint(null);
SessionPseudoClock clock = (SessionPseudoClock) ep.getReteEvaluator().getSessionClock();
long advanceTime = timestamp - clock.getCurrentTime();
if (advanceTime > 0) {
clock.advanceTime(advanceTime, TimeUnit.MILLISECONDS);
} else if (advanceTime < 0) {
LOGGER.warn("Received an event with a timestamp that is " + (-advanceTime) + " milliseconds in the past. " + "Evaluation of out of order events could lead to unpredictable results.");
}
}
use of org.drools.core.WorkingMemoryEntryPoint in project drools by kiegroup.
the class RuleUnitExecutorImpl method initInitialFact.
private void initInitialFact(RuleBase kBase) {
WorkingMemoryEntryPoint defaultEntryPoint = entryPointsManager.getDefaultEntryPoint();
InternalFactHandle handle = getFactHandleFactory().newInitialFactHandle(defaultEntryPoint);
ObjectTypeNode otn = defaultEntryPoint.getEntryPointNode().getObjectTypeNodes().get(InitialFact_ObjectType);
if (otn != null) {
PropagationContextFactory ctxFact = RuntimeComponentFactory.get().getPropagationContextFactory();
PropagationContext pctx = ctxFact.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, handle, defaultEntryPoint.getEntryPoint(), null);
otn.assertInitialFact(handle, pctx, this);
}
}
use of org.drools.core.WorkingMemoryEntryPoint in project drools by kiegroup.
the class FactHandleMarshallingTest method createEventFactHandle.
private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
// EntryPointNode
Rete rete = kBase.getRete();
NodeFactory nFacotry = CoreComponentFactory.get().getNodeFactoryService();
RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, rete, EntryPointId.DEFAULT);
WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
EventFactHandle factHandle = new EventFactHandle(1, new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint);
return factHandle;
}
use of org.drools.core.WorkingMemoryEntryPoint in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method reset.
public void reset(long handleId, long handleCounter, long propagationCounter) {
if (nodeMemories != null) {
nodeMemories.clear();
}
this.agenda.clear();
for (WorkingMemoryEntryPoint ep : this.entryPointsManager.getEntryPoints()) {
// clear the state for each entry point
ep.reset();
}
this.handleFactory.clear(handleId, handleCounter);
this.propagationIdCounter = new AtomicLong(propagationCounter);
this.lastIdleTimestamp.set(-1);
// TODO should these be cleared?
// we probably neeed to do CEP and Flow timers too
// this.processInstanceManager.clear()
// this.workItemManager.clear();
}
Aggregations