use of org.drools.mvel.compiler.StockTickInterface in project drools by kiegroup.
the class PseudoClockEventsTest method processStocks.
private int processStocks(int stockCount, AgendaEventListener agendaEventListener, String drlContentString) throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drlContentString);
KieSessionConfiguration ksessionConfig = RuleBaseFactory.newKnowledgeSessionConfiguration();
ksessionConfig.setOption(ClockTypeOption.PSEUDO);
ksessionConfig.setProperty("keep.reference", "true");
final KieSession ksession = kbase.newKieSession(ksessionConfig, null);
ksession.addEventListener(agendaEventListener);
PseudoClockScheduler clock = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
Thread fireUntilHaltThread = new Thread(ksession::fireUntilHalt, "Engine's thread");
fireUntilHaltThread.start();
try {
Thread.currentThread().setName("Feeding thread");
for (int stIndex = 1; stIndex <= stockCount; stIndex++) {
clock.advanceTime(20, TimeUnit.SECONDS);
Thread.sleep(100);
final StockTickInterface st = new StockTick(stIndex, "RHT", 100 * stIndex, 100 * stIndex);
ksession.insert(st);
Thread.sleep(100);
}
Thread.sleep(100);
} finally {
ksession.halt();
ksession.dispose();
}
fireUntilHaltThread.join(5000);
return stockCount;
}
Aggregations