use of org.drools.core.spi.GlobalResolver in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method init.
private void init(SessionConfiguration config, Environment environment, long propagationContext) {
this.config = config;
this.environment = environment;
this.propagationIdCounter = new AtomicLong(propagationContext);
Globals globals = (Globals) this.environment.get(EnvironmentName.GLOBALS);
if (globals != null) {
if (!(globals instanceof GlobalResolver)) {
this.globalResolver = new GlobalsAdapter(globals);
} else {
this.globalResolver = (GlobalResolver) globals;
}
} else {
this.globalResolver = new MapGlobalResolver();
}
this.kieBaseEventListeners = new LinkedList<KieBaseEventListener>();
this.lock = new ReentrantLock();
this.timerService = TimerServiceFactory.getTimerService(this.config);
this.opCounter = new AtomicLong(0);
this.lastIdleTimestamp = new AtomicLong(-1);
}
use of org.drools.core.spi.GlobalResolver 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.spi.GlobalResolver in project drools by kiegroup.
the class ReteooWorkingMemoryTest method testGlobalResolver.
@Test
public void testGlobalResolver() {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("global1", "value1");
map.put("global2", "value2");
final GlobalResolver resolver = new MapGlobalResolver(map);
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
ksession.setGlobalResolver(resolver);
assertEquals("value1", ksession.getGlobal("global1"));
assertEquals("value2", ksession.getGlobal("global2"));
}
Aggregations