See below. On 07/12/2011, MarcoMojana <marco.moj...@exmachina.ch> wrote: > I have set the session clock type to pseudo, the processing mode is still > stream and I have added the following rule: > > rule "SingleEvent" > dialect "mvel" > when > $e0 : TriggerEvent() over window:time(1h) from entry-point > EventStream > then > System.err.println("SingleEvent " + $e0); > end > > And I have changed the code in the following way: > > eventStream.insert(new InhibitEvent(new GregorianCalendar(2011, > Calendar.DECEMBER, 6, 12, 0, 0).getTime())); > eventStream.insert(new TriggerEvent(new GregorianCalendar(2011, > Calendar.DECEMBER, 6, 13, 0, 0).getTime())); > eventStream.insert(new InhibitEvent(new GregorianCalendar(2011, > Calendar.DECEMBER, 6, 14, 0, 0).getTime())); > eventStream.insert(new TriggerEvent(new GregorianCalendar(2011, > Calendar.DECEMBER, 6, 14, 10, 0).getTime())); > EventFactHandle lastEventHandle = (EventFactHandle) eventStream.insert(new > InhibitEvent(new GregorianCalendar(2011, Calendar.DECEMBER, 6, 14, 20, > 0).getTime())); > > System.err.println("The session clock is set to: " + new > Date(pseudoClock.getCurrentTime())); > ksession.fireAllRules(); > System.err.println("The session clock is set to: " + new > Date(pseudoClock.getCurrentTime())); > > It prints: > > The session clock is set to: Thu Jan 01 01:00:00 CET 1970 > SingleEvent TriggerEvent [timestamp=Tue Dec 06 14:10:00 CET 2011] > SingleEvent TriggerEvent [timestamp=Tue Dec 06 13:00:00 CET 2011] > The session clock is set to: Thu Jan 01 01:00:00 CET 1970 > > This means that, with a pseudo clock, even if you don't update it, > drools will consider also the events happening after it (The events are > inserted in the entry-point, not as facts). In my opinion this doesn't > make any sense.
With the pseudo clock set to the begin of the epoch you run Drools as if we had 1970. Drools refuses to believe that it is fed events that are in the future; asking it to locate events that have happened not earlier than one hour ago includes those with a timestamp that is in the future. > > Adding others fireAllRules() and clock updates doesn't change the output. > What am I doing wrong? Do you really set the pseudo clock to the values in the timestamps? set the clock insert the event fire all rules > > Now I would like to trigger also the "EventNotInhibited" rule. I have > defined a method that updates the session clock in one big step: > > private static void advanceSessionClock(StatefulKnowledgeSession ksession, > long time) { > > final SessionPseudoClock pseudoClock = ksession.getSessionClock(); > > final long advance = time - pseudoClock.getCurrentTime(); > if(advance > 0) > pseudoClock.advanceTime(advance, TimeUnit.MILLISECONDS); > ksession.fireAllRules(); > I would not call fireAllRules here - see the pseudo-code above. The arrival of an event with timestamp T should happen when the clock points at T. -W _______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users