use of org.drools.core.SessionConfiguration 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.drools.core.SessionConfiguration in project drools by kiegroup.
the class FactHandleMarshallingTest method createWorkingMemory.
private StatefulKnowledgeSessionImpl createWorkingMemory(InternalKnowledgeBase kBase) {
// WorkingMemoryEntryPoint
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("pseudo"));
SessionConfiguration sessionConf = ((SessionConfiguration) ksconf);
StatefulKnowledgeSessionImpl wm = new StatefulKnowledgeSessionImpl(1L, kBase, true, sessionConf, EnvironmentFactory.newEnvironment());
return wm;
}
use of org.drools.core.SessionConfiguration in project drools by kiegroup.
the class MarshallingTest method testScheduledActivation.
@Test
@Ignore("This test is suspicious to say the least...")
public void testScheduledActivation() {
KnowledgeBaseImpl knowledgeBase = (KnowledgeBaseImpl) KnowledgeBaseFactory.newKnowledgeBase();
KnowledgePackageImpl impl = new KnowledgePackageImpl("test");
BuildContext buildContext = new BuildContext(knowledgeBase);
// simple rule that fires after 10 seconds
final RuleImpl rule = new RuleImpl("test-rule");
new RuleTerminalNode(1, new MockTupleSource(2), rule, rule.getLhs(), 0, buildContext);
final List<String> fired = new ArrayList<String>();
rule.setConsequence(new Consequence() {
public void evaluate(KnowledgeHelper knowledgeHelper, WorkingMemory workingMemory) throws Exception {
fired.add("a");
}
public String getName() {
return "default";
}
});
rule.setTimer(new DurationTimer(10000));
rule.setPackage("test");
impl.addRule(rule);
knowledgeBase.addPackages(Collections.singleton(impl));
SessionConfiguration config = SessionConfiguration.newInstance();
config.setClockType(ClockType.PSEUDO_CLOCK);
KieSession ksession = knowledgeBase.newKieSession(config, KieServices.get().newEnvironment());
PseudoClockScheduler scheduler = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
Marshaller marshaller = MarshallerFactory.newMarshaller(knowledgeBase);
ksession.insert("cheese");
assertTrue(fired.isEmpty());
// marshall, then unmarshall session
readWrite(knowledgeBase, ksession, config);
// the activations should fire after 10 seconds
assertTrue(fired.isEmpty());
scheduler.advanceTime(12, TimeUnit.SECONDS);
assertFalse(fired.isEmpty());
}
use of org.drools.core.SessionConfiguration in project drools by kiegroup.
the class BayesBeliefSystemTest method getSession.
protected KieSession getSession(String ruleFile) {
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(ResourceFactory.newClassPathResource(ruleFile), ResourceType.DRL);
if (kBuilder.hasErrors()) {
System.err.println(kBuilder.getErrors());
fail();
}
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
kBase.addPackages(kBuilder.getKnowledgePackages());
KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
((SessionConfiguration) ksConf).setBeliefSystemType(BeliefSystemType.DEFEASIBLE);
KieSession kSession = kBase.newKieSession(ksConf, null);
return kSession;
}
use of org.drools.core.SessionConfiguration in project drools by kiegroup.
the class AbductionTest method getSessionFromString.
protected KieSession getSessionFromString(String drlString, KieBaseConfiguration kbConf) {
KieHelper kieHelper = new KieHelper();
kieHelper.addContent(drlString, ResourceType.DRL);
Results res = kieHelper.verify();
if (res.hasMessages(Message.Level.ERROR)) {
fail(res.getMessages(Message.Level.ERROR).toString());
}
if (kbConf == null) {
kbConf = KieServices.Factory.get().newKieBaseConfiguration();
}
kbConf.setOption(EqualityBehaviorOption.EQUALITY);
KieBase kieBase = kieHelper.build(kbConf);
KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
((SessionConfiguration) ksConf).setBeliefSystemType(BeliefSystemType.DEFEASIBLE);
return kieBase.newKieSession(ksConf, null);
}
Aggregations