use of org.drools.core.marshalling.impl.ProtobufMessages.Timers.Timer in project drools by kiegroup.
the class ProtobufInputMarshaller method readSession.
public static StatefulKnowledgeSessionImpl readSession(ProtobufMessages.KnowledgeSession _session, StatefulKnowledgeSessionImpl session, InternalAgenda agenda, MarshallerReaderContext 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);
}
// RuleFlowGroups need to reference the session
// for ( InternalAgendaGroup group : agenda.getAgendaGroupsMap().values() ) {
// ((RuleFlowGroupImpl) group).setWorkingMemory( session );
// }
context.wm = 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.kBase, context));
context.handles.put(session.getInitialFactHandle().getId(), session.getInitialFactHandle());
}
for (ProtobufMessages.EntryPoint _ep : _session.getRuleData().getEntryPointList()) {
EntryPoint wmep = ((StatefulKnowledgeSessionImpl) context.wm).getEntryPointMap().get(_ep.getEntryPointId());
readFactHandles(context, _ep, ((WorkingMemoryEntryPoint) wmep).getObjectStore(), pctxs);
context.filter.fireRNEAs(context.wm);
readTruthMaintenanceSystem(context, wmep, _ep, pctxs);
}
cleanReaderContexts(pctxs);
readActionQueue(context, _session.getRuleData());
if (processMarshaller != null) {
if (_session.hasProcessData()) {
context.parameterObject = _session.getProcessData();
processMarshaller.readProcessInstances(context);
context.parameterObject = _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.parameterObject = _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.impl.ProtobufMessages.Timers.Timer in project drools by kiegroup.
the class ProtobufOutputMarshaller method writeTimers.
private static ProtobufMessages.Timers writeTimers(Collection<TimerJobInstance> timers, MarshallerWriteContext outCtx) {
if (!timers.isEmpty()) {
List<TimerJobInstance> sortedTimers = new ArrayList<TimerJobInstance>(timers);
Collections.sort(sortedTimers, new Comparator<TimerJobInstance>() {
public int compare(TimerJobInstance o1, TimerJobInstance o2) {
return (int) (o1.getJobHandle().getId() - o2.getJobHandle().getId());
}
});
ProtobufMessages.Timers.Builder _timers = ProtobufMessages.Timers.newBuilder();
for (TimerJobInstance timer : sortedTimers) {
JobContext jctx = ((SelfRemovalJobContext) timer.getJobContext()).getJobContext();
if (jctx instanceof ObjectTypeNode.ExpireJobContext && !((ObjectTypeNode.ExpireJobContext) jctx).getExpireAction().getFactHandle().isValid()) {
continue;
}
TimersOutputMarshaller writer = outCtx.writersByClass.get(jctx.getClass());
Timer _timer = writer.serialize(jctx, outCtx);
if (_timer != null) {
_timers.addTimer(_timer);
}
}
return _timers.build();
}
return null;
}
Aggregations