[rules-users] Sliding window behavior in stream mode and realtime clock
Wolfgang Laun
wolfgang.laun at gmail.com
Wed Dec 7 07:06:05 EST 2011
With the rules you gave, in STREAM mode and with a pseudo clock and
running 5.2.0:
SessionPseudoClock clock;
private void advance( Date eventDate ){
long currentTime = clock.getCurrentTime();
long eventTime = eventDate.getTime();
clock.advanceTime( eventTime - currentTime, TimeUnit.MILLISECONDS );
}
private void makeFacts(){
clock = kSession.getSessionClock();
WorkingMemoryEntryPoint eventStream =
kSession.getWorkingMemoryEntryPoint( "EventStream" );
InhibitEvent inhibit;
TriggerEvent trigger;
inhibit = new InhibitEvent( new GregorianCalendar(2011,
Calendar.DECEMBER, 6,
12, 0, 0).getTime() );
advance( inhibit.getTimestamp() );
eventStream.insert( inhibit );
kSession.fireAllRules();
// proceed likewise with events at 1300, 1400, 1410, 1420
Output:
SingleEvent TriggerEvent [timestamp=Tue Dec 06 13:00:00 CET 2011]
Found TriggerEvent [timestamp=Tue Dec 06 13:00:00 CET 2011]
SingleEvent TriggerEvent [timestamp=Tue Dec 06 14:10:00 CET 2011]
On 07/12/2011, MarcoMojana <marco.mojana at exmachina.ch> wrote:
>
> laune wrote
>>
>> Do you really set the pseudo clock to the values in the timestamps?
>> set the clock
>> insert the event
>> fire all rules
>>
>
> Now, if I do:
> set the clock
> fire all rules
> insert the event
>
> i.e., something like this:
>
> nextEventTime = new GregorianCalendar(2011, Calendar.DECEMBER, 6, 12, 10,
> 0).getTime();
> advanceSessionClock(ksession, nextEventTime.getTime());
> System.err.println("Firing rules");
> ksession.fireAllRules();
> System.err.println("Inserting event");
> eventStream.insert(new InhibitEvent(nextEventTime));
>
> everything works unexpectedly correctly. It works even when the clock is
> updated in one single step (instead of once per second). Doing the three
> steps in the sequence you suggested, i.e.
>
> nextEventTime = new GregorianCalendar(2011, Calendar.DECEMBER, 6, 12, 10,
> 0).getTime();
> advanceSessionClock(ksession, nextEventTime.getTime());
> System.err.println("Inserting event");
> eventStream.insert(new InhibitEvent(nextEventTime));
> System.err.println("Firing rules");
> ksession.fireAllRules();
>
> never triggers the rule. Have you an idea why this happens?
> Does it exists a configuration option that implicitly updates the session
> clock with that of the last inserted event if the latter is in the future?
>
> --
>
> MM
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Sliding-window-behavior-in-stream-mode-and-realtime-clock-tp3564950p3567049.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list