[rules-users] Event insert to session with 'not( after this..)'

Wolfgang Laun wolfgang.laun at gmail.com
Sat Feb 23 01:00:20 EST 2013


A session in STREAM mode using the realtime clock is based on the
assumption that its start is something like the "Big Bang": nothing
has happened before that, not even Time.

There are two possibilities for solving your problem.

(1) Use a timer-based rule to monitor the end of the 50 hours. I've
used 1m as the timer's granularity: this depends on the precision you
require, but if you don't have to watch many Signature's at the same
time, 1s shouldn't create a problem.

rule "monitor"
timer( int: 1m 1m )
when
    $t: Signature()
    not Signature( this != $t, this after $t )
then
    if( System.currentTimeMillis() - $t.getTimestamp() >= 50.MS_PER_H ){
        retract( $t );
    }
end

(2) Run the session using a pseudo-clock. This lets you "replay" the
time before the "Big Bang", advancing the clock according to the
timestamps of the deserialized (past) events. Then, you advance the
clock to now, and continue to advance it according to the system
clock, using a java.util.Timer. (Or based on the timestamps of
arriving events - it depends.)

Although more elaborate, there are some additional advantages with the
second solution.

-W






On 19/02/2013, RichardAmbridge <richard.ambridge at gmail.com> wrote:
> If I declare an event like:
>
> declare Signature
>  @role ( event )
>  @timestamp(timestamp)
> end
>
> where timestamp is a long value set to the System.currentTimestamp()
>
>
> and if I have a rule that has in it
> $s : Signature(name=="YYYY")
> not(Signature(name=="XXX", this after [0s,50h] $s))
>
>
> If i insert a Signature that has name=YYYY, then after 50 hours this rule
> will fire.. which is great.
>
> However, we have a situation where sometimes we need to reload all our
> rules.
> Today, I grab all the Objects from the session
> engine.getKsession().getObjects()
> and store them in a file (serialize), then recreate the session and
> reinsert
> all the objects again.
>
> However, this resets the time window for the event...
> So if i insert Signature with name=YYYY,  wait 48 hours, reload the session
> then the rule will not fire for another 50 hours, instead of in 2 hours
> time.
>
> The value of @timestamp is still set to the original time (48 hours ago)
> and
> if I check
> EventFactHandle handle=(EventFactHandle) ksession.insert(s);
> handle.getStartTimestamp();
> the value of StartTimestamp is set to 48 hours ago..
>
> Is there anyway I can get the rule to fire at the correct time?
>
> Many thanks
> Ric
>
> Running Drools 5.3.0
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Event-insert-to-session-with-not-after-this-tp4022455.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