From greg_barton at yahoo.com Sat May 2 18:11:23 2009 Content-Type: multipart/mixed; boundary="===============1084429011632399523==" MIME-Version: 1.0 From: Greg Barton To: rules-users at lists.jboss.org Subject: Re: [rules-users] Retraction of facts based on time - any ideas please? Date: Sat, 02 May 2009 15:09:14 -0700 Message-ID: <168495.6742.qm@web81503.mail.mud.yahoo.com> In-Reply-To: 20090430033824.0fcc8502db30fb9baeee71277b2015cf.6955ed15c1.wbe@email.secureserver.net --===============1084429011632399523== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable If you can use Drools 5, then try out event expiration in stream mode using= drools fusion: https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/tru= nk/target/docs/drools-fusion/html_single/index.html#d0e1086 If you can't do that, you'll need an extra control object that's inserted p= eriodically. Let's call it Heartbeat: ` rule "Retract expired facts" dialect"mvel" // salience -5 when h : Heartbeat(); e1 : Event (code =3D=3D "LOGON", status =3D=3D "ACTIVE") eval ((h.getLongTimeStamp() - e1.getLongTimeStamp()) > 100) then System.out.println( "Retracting expired event with Timestamp: " + e1.lo= ngTimeStamp ); retract (e1); end And you'll require an extra rule to cleanup the Heartbeat. It should be lo= wer priority than all other retract rules: rule "Retract heartbeat" salience -1000 when h : Heartbeat(); then = retract(h); end Finally, you'll have to set up a java.util.Timer or a java.util.concurrent.= ScheduledExecutorService to periodically insert a new Heartbeat into workin= g memory. Again, Drools 5 fusion handles all of this. All you do is declare an objec= t as an event, then define it's expiration time. --- On Thu, 4/30/09, rsundaar(a)aretus.biz wrote: > From: rsundaar(a)aretus.biz > Subject: [rules-users] Retraction of facts based on time - any ideas plea= se? > To: "Rules Users List" > Date: Thursday, April 30, 2009, 5:38 AM >
style=3D"font-family:Verdana;color:#000000;font-size:10pt;">
=C2=A0 >
I have a need to "expire" some facts > based on time. In other words, if an event occurs some time > and if sufficient time has gone by, the fact should become > inonsequential and be retracted. Here is my simple rule to > do this:
>
=C2=A0
size=3D"2"> >
align=3D"left"> color=3D"#960000" size=3D"2"> color=3D"#960000" > size=3D"2"> size=3D"2"> size=3D"2">
>
align=3D"left"> color=3D"#960000" size=3D"2"> color=3D"#960000" > size=3D"2">rule size=3D"2"> color=3D"#008000" size=3D"2"> color=3D"#008000" > size=3D"2">"Retract expired > facts"
>
align=3D"left"> size=3D"2">
>
align=3D"left"> color=3D"#960000" size=3D"2"> color=3D"#960000" > size=3D"2">dialect size=3D"2"> color=3D"#008000" size=3D"2"> color=3D"#008000" > size=3D"2">"mvel"
>
align=3D"left"> size=3D"2">
>
color=3D"#808000" size=3D"2"> color=3D"#808000" size=3D"2">// salience > -5
>
align=3D"left"> size=3D"2">
>
align=3D"left"> color=3D"#960000" size=3D"2"> color=3D"#960000" > size=3D"2">when
>
align=3D"left"> size=3D"2">
>
e1 : Event (code =3D=3D > size=3D"2"> size=3D"2">"LOGON" size=3D"2">, status =3D=3D color=3D"#008000" size=3D"2"> color=3D"#008000" > size=3D"2">"ACTIVE" size=3D"2">)
>
align=3D"left"> color=3D"#960000" size=3D"2"> color=3D"#960000" > size=3D"2">eval size=3D"2"> ((getCurrentTimeStamp ()- > e1.getLongTimeStamp()) > size=3D"2">100) size=3D"2">
>
align=3D"left"> color=3D"#960000" size=3D"2"> color=3D"#960000" > size=3D"2">then size=3D"2">
>
System.out.println( > size=3D"2"> size=3D"2">"Retracting expired event with > Timestamp: " size=3D"2"> + e1.longTimeStamp );
>
align=3D"left"> color=3D"#960000" size=3D"2"> color=3D"#960000" > size=3D"2">retract size=3D"2"> (e1);
>
>
>
color=3D"#960000" size=3D"2"> color=3D"#960000" size=3D"2">
>
end
>
=C2=A0
>
This does > not seem to work because the "eval" method does > not evaluate the rule every cycle. And, there is no other > change to the fact (event) to force the rule to re-evaluate > the fact. Is there a way to make "eval" in the LHS > evaluate every cycle? Is there any other > method?
>
color=3D"#000000">=C2=A0
>
I would > greatly appreciate any ideas.
>
=C2=A0
>
color=3D"#000000">Thanks,
>

color=3D"#000000">Ravi. size=3D"2">

> = >
_______________________________________________ > rules-users mailing list > rules-users(a)lists.jboss.org > https://lists.jboss.org/mailman/listinfo/rules-users = --===============1084429011632399523==--