Search in sources :

Example 1 with StockTickInterface

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;
}
Also used : StockTickInterface(org.drools.mvel.compiler.StockTickInterface) StockTick(org.drools.mvel.compiler.StockTick) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) PseudoClockScheduler(org.drools.core.time.impl.PseudoClockScheduler)

Aggregations

PseudoClockScheduler (org.drools.core.time.impl.PseudoClockScheduler)1 StockTick (org.drools.mvel.compiler.StockTick)1 StockTickInterface (org.drools.mvel.compiler.StockTickInterface)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)1