private StatefulKnowledgeSession createSession(KnowledgeBase kbase) { final KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId())); StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, conf, createEnvironment()); return ksession; }
private StatefulKnowledgeSession disposeAndReloadSession( StatefulKnowledgeSession ksession, KnowledgeBase kbase) { int ksessionId = ksession.getId(); ksession.dispose(); final KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId())); StatefulKnowledgeSession newksession = JPAKnowledgeService.loadStatefulKnowledgeSession( ksessionId, kbase, conf, createEnvironment()); return newksession; }
@Before public void setUp() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( new ClassPathResource("imports-and-declarations.drl", getClass()), ResourceType.DRL); kbuilder.add(new ClassPathResource("discussion.drl", getClass()), ResourceType.DRL); Assert.assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors()); KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); config.setOption(EventProcessingOption.STREAM); kbase = KnowledgeBaseFactory.newKnowledgeBase(config); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); conf.setOption(ClockTypeOption.get("pseudo")); ksession = kbase.newStatefulKnowledgeSession(conf, null); firedRules = new FiredRulesListener(); ksession.addEventListener(firedRules); notificationsGeneral = new NotificationsGeneralChannelMock(); ksession.registerChannel("notificationsGeneral", notificationsGeneral); }