private void testEventsExpiredInThePast(final String drl) { final KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); sessionConfig.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); final KieHelper helper = new KieHelper(); helper.addContent( drl, ResourceType.DRL ); final KieBase kieBase = helper.build( EventProcessingOption.STREAM ); final KieSession kieSession = kieBase.newKieSession( sessionConfig, null ); PseudoClockScheduler clock = kieSession.getSessionClock(); final long currentTime = clock.getCurrentTime(); clock.advanceTime(100, TimeUnit.MILLISECONDS); kieSession.insert(new BasicEvent(new Date(currentTime + 20), 10L, "20ms-30ms")); clock.advanceTime(1, TimeUnit.MILLISECONDS); kieSession.insert(new BasicEvent(new Date(currentTime + 20), 20L, "20ms-40ms")); clock.advanceTime(100, TimeUnit.MILLISECONDS); Assertions.assertThat(kieSession.fireAllRules()).isEqualTo(1); clock.advanceTime(10, TimeUnit.MILLISECONDS); Assertions.assertThat(kieSession.getObjects()).isEmpty(); } }
"end"; KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); sessionConfig.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); .newKieSession( sessionConfig, null ); PseudoClockScheduler sessionClock = ksession.getSessionClock(); sessionClock.setStartupTime( 0 ); ksession.setGlobal( "counter", counter ); new Thread( () -> ksession.fireUntilHalt() ).start();
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); kbase.addPackages(Arrays.asList(builder.getPackages())); conf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); SessionPseudoClock clock = ( SessionPseudoClock) session.getSessionClock(); clock.advanceTime( 300, TimeUnit.MILLISECONDS ); session.setGlobal("myList", myList); ProcessInstance processInstance = ( ProcessInstance ) session.startProcess("org.drools.timer"); assertEquals(0, myList.size()); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel( KSESSION1 ).setDefault( true ) .setType( KieSessionModel.KieSessionType.STATEFUL ) .setClockType( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); KieBase kiebase = kc.getKieBase( KBASE1 ); KieSessionConfiguration sessionConf = ks.newKieSessionConfiguration(); sessionConf.setOption(ForceEagerActivationOption.YES); KieSession ksession = kc.newKieSession(KSESSION1, sessionConf); assertFalse( aggrMonitor.getStatsByRule().containsKey("ND2") ); ksession.insert("Ciao"); ksession.fireAllRules(); print(aggrMonitor); checkAgendaTotals(aggrMonitor, 2, 1, 1); checkStatsByRule(aggrMonitor,"ND2",1,0,1); ksession.fireAllRules(); print(aggrMonitor); checkAgendaTotals(aggrMonitor, 2, 1, 1);
/** * Initialisation of Drools stateful session without convention and kodmule files. * * @param ruleFiles * DRL files */ public static synchronized void initFromRulesFiles(Set < String > ruleFiles) { if (isInitialized()) { throw new IllegalStateException("This Factory has already be initialized once"); } _instance = new FF4jDroolsService(); _instance.ruleFiles = ruleFiles; KieHelper helper = new KieHelper(); KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId())); //ruleFiles.stream().forEach(drlFile -> helper.addContent(loadResourceAsString(drlFile), ResourceType.determineResourceType(drlFile))); for (String drlFile : ruleFiles) { String fileContent = loadResourceAsString(drlFile); ResourceType typeFile = ResourceType.determineResourceType(drlFile); helper.addContent(fileContent, typeFile); } _instance.ksession = helper.build(EventProcessingOption.STREAM).newKieSession(sessionConfig, null); }
@Before public void setUp() { final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add( ResourceFactory.newByteArrayResource( drl.getBytes() ), ResourceType.DRL); if (kbuilder.hasErrors()) { System.err.println(kbuilder.getErrors().toString()); } final KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); config.setOption( EventProcessingOption.STREAM); final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config); kbase.addPackages(kbuilder.getKnowledgePackages()); final KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); sessionConfig.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() )); this.statefulSession = kbase.newKieSession(sessionConfig, null); this.stockFactory = new StockFactory(kbase); }
KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel( KSESSION1 ).setDefault( true ) .setType( KieSessionModel.KieSessionType.STATEFUL ) .setClockType( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); KieBase kiebase = kc.getKieBase( KBASE1 ); kc.newKieSession(KSESSION1); kiebase.newKieSession();
private StatefulKnowledgeSession createSession(KieBase kbase) { final KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); conf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); StatefulKnowledgeSession ksession = InfinispanKnowledgeService.newStatefulKnowledgeSession( kbase, conf, createEnvironment(context) ); return ksession; }
rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));
KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); sessionConfig.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); .newKieSession( sessionConfig, null ); PseudoClockScheduler sessionClock = ksession.getSessionClock(); sessionClock.setStartupTime(0); done1.countDown(); }} ); ksession.setGlobal( "list", list ); ksession.insert( new MyEvent( i, i*2L ) );
private StatefulKnowledgeSession disposeAndReloadSession(StatefulKnowledgeSession ksession, KieBase kbase) { long ksessionId = ksession.getIdentifier(); ksession.dispose(); final KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); conf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); StatefulKnowledgeSession newksession = InfinispanKnowledgeService.loadStatefulKnowledgeSession( ksessionId, kbase, conf, createEnvironment(context) ); return newksession; }
rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));
private void checkPrice( String drl, double expectedPrice ) { KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(); sessionConfig.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) ); KieSession ksession = new KieHelper().addContent( drl, ResourceType.DRL ) .build( EventProcessingOption.STREAM ) .newKieSession( sessionConfig, null ); List<Double> list = new ArrayList<Double>(); ksession.setGlobal( "list", list ); ksession.insert( "RHT" ); ksession.insert( new StockTick( 1L, "RHT", 10.0 ) ); ksession.insert( new StockTick( 2L, "RHT", 10.0 ) ); ksession.insert( new StockTick( 3L, "ABC", 20.0 ) ); ksession.insert( new StockTick( 4L, "RHT", 10.0 ) ); ksession.insert( new StockTick( 5L, "XYZ", 20.0 ) ); ksession.insert( new StockTick( 6L, "XYZ", 20.0 ) ); ksession.insert( new StockTick( 7L, "RHT", 10.0 ) ); ksession.fireAllRules(); assertEquals( 1, list.size() ); assertEquals( expectedPrice, (double)list.get(0), 0.01 ); }
if (e != null && StringUtils.hasText(e.getAttribute("type"))) { rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));