窗口时间结束后,Drools Windowing正在执行其他规则

时间:2018-08-06 12:43:41

标签: drools kie drools-fusion drools-flow

我正在使用Drool Fusion执行窗口规则。以下是我的Test类:

public class Test {
    int count;

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Test(int count) {
        this.count = count;
    }
}

当我尝试执行以下规则时,我得到了意外的结果:

declare Test
@role(event)
@timestamp(time)
@expires(10m)
end


rule "Sliding window test1"
agenda-group "g0"
when
    $number: Number() from accumulate(Test($t:count <10) over window:time(10s) , average($t))
then
   System.out.println("Test Rule 1 " + $number );
end

rule "Sliding window test2"
agenda-group "g0"
when
    $number: Number() from accumulate(Test($t:count >10 ) over window:time(10s) , average($t))
then
   System.out.println("Test Rule 2 " + $number );
end
  

响应:窗口规则结束后,即10 seconds,两个规则都被触发。

我的实施者是:

public static void main(String[] args) throws InterruptedException {
        KieServices kieServices = KieServices.Factory.get();
        KieContainer kieContainer = kieServices.getKieClasspathContainer();
        KieSession kieSession = kieContainer.newKieSession("window-session");
        SessionPseudoClock clock = kieSession.getSessionClock();
        long curr = System.currentTimeMillis();
        while(true) {
            long time = System.currentTimeMillis();
            for(int i=0;i<20;i++) {
                Test test = new Test(i);
                kieSession.insert(test);
                kieSession.getAgenda().getAgendaGroup("g0").setFocus();
                clock.advanceTime(time - clock.getCurrentTime(), TimeUnit.MILLISECONDS);
                kieSession.fireAllRules();
                System.out.println(System.currentTimeMillis() - curr);
                Thread.sleep(10); //historical event test
            }
        }
    }

我得到了意外的输出,即10秒后,两个规则都在1秒后触发,并重复了相同的操作。此行为仅在我使用Pseudo clock时发生。 请帮助

0 个答案:

没有答案