use of org.kie.api.runtime.Globals 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.kie.api.runtime.Globals in project drools by kiegroup.
the class StatelessKnowledgeSessionImpl method newWorkingMemory.
public StatefulKnowledgeSession newWorkingMemory() {
this.kBase.readLock();
try {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) wmFactory.createWorkingMemory(this.kBase.nextWorkingMemoryCounter(), this.kBase, (SessionConfiguration) this.conf, this.environment);
StatefulKnowledgeSessionImpl ksessionImpl = (StatefulKnowledgeSessionImpl) ksession;
((Globals) ksessionImpl.getGlobalResolver()).setDelegate(this.sessionGlobals);
registerListeners(ksessionImpl);
for (Map.Entry<String, Channel> entry : this.channels.entrySet()) {
ksession.registerChannel(entry.getKey(), entry.getValue());
}
wmCreated.incrementAndGet();
return ksession;
} finally {
this.kBase.readUnlock();
}
}
use of org.kie.api.runtime.Globals in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeSameSessionRemovingGlobal.
@Test
public void testKJarUpgradeSameSessionRemovingGlobal() throws Exception {
// DROOLS-752
String drl1 = "package org.drools.compiler\n" + "global java.lang.String foo\n" + "global java.lang.String bar\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
String drl2 = "package org.drools.compiler\n" + "global java.lang.String foo\n" + "global java.lang.String baz\n" + "rule R2 when\n" + " $m : Message( )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.setGlobal("foo", "foo");
ksession.setGlobal("bar", "bar");
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
km = createAndDeployJar(ks, releaseId2, drl2);
kc.updateToVersion(releaseId2);
ksession.setGlobal("baz", "baz");
Globals globals = ksession.getGlobals();
assertEquals(2, globals.getGlobalKeys().size());
assertEquals("foo", ksession.getGlobal("foo"));
assertNull(ksession.getGlobal("bar"));
assertEquals("baz", ksession.getGlobal("baz"));
}
use of org.kie.api.runtime.Globals in project drools by kiegroup.
the class RuleUnitExecutorSession method bindRuleUnit.
private RuleUnitDescr bindRuleUnit(RuleUnit ruleUnit) {
suspended.set(false);
currentRuleUnit = ruleUnit;
currentRuleUnit.onStart();
factHandlesMap.computeIfAbsent(ruleUnit.getClass(), x -> session.getEntryPoint(RULE_UNIT_ENTRY_POINT).insert(ruleUnit));
RuleUnitDescr ruDescr = session.kBase.getRuleUnitRegistry().getRuleUnitDescr(ruleUnit);
ruDescr.bindDataSources(session, ruleUnit);
((Globals) session.getGlobalResolver()).setDelegate(new RuleUnitGlobals(ruDescr, ruleUnit));
InternalAgendaGroup unitGroup = (InternalAgendaGroup) session.getAgenda().getAgendaGroup(ruleUnit.getClass().getName());
unitGroup.setAutoDeactivate(false);
unitGroup.setFocus();
return ruDescr;
}
use of org.kie.api.runtime.Globals in project drools by kiegroup.
the class MarshallingTest method marsallStatefulKnowledgeSession.
private KieSession marsallStatefulKnowledgeSession(KieSession ksession) throws IOException, ClassNotFoundException {
Globals globals = ksession.getGlobals();
KieBase kbase = ksession.getKieBase();
ByteArrayOutputStream out = new ByteArrayOutputStream();
MarshallerFactory.newMarshaller(kbase).marshall(out, ksession);
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(TimerJobFactoryOption.get("trackable"));
ksconf.setOption(ClockTypeOption.get("pseudo"));
Environment env = EnvironmentFactory.newEnvironment();
env.set(EnvironmentName.GLOBALS, globals);
ksession = MarshallerFactory.newMarshaller(kbase).unmarshall(new ByteArrayInputStream(out.toByteArray()), ksconf, env);
return ksession;
}
Aggregations