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/t...
If you can't do that, you'll need an extra control object that's inserted
periodically. Let's call it Heartbeat: `
rule "Retract expired facts"
dialect"mvel"
// salience -5
when
h : Heartbeat();
e1 : Event (code == "LOGON", status == "ACTIVE")
eval ((h.getLongTimeStamp() - e1.getLongTimeStamp()) > 100)
then
System.out.println( "Retracting expired event with Timestamp: " +
e1.longTimeStamp );
retract (e1);
end
And you'll require an extra rule to cleanup the Heartbeat. It should be lower
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
working memory.
Again, Drools 5 fusion handles all of this. All you do is declare an object as an event,
then define it's expiration time.
--- On Thu, 4/30/09, rsundaar(a)aretus.biz <rsundaar(a)aretus.biz> wrote:
From: rsundaar(a)aretus.biz <rsundaar(a)aretus.biz>
Subject: [rules-users] Retraction of facts based on time - any ideas please?
To: "Rules Users List" <rules-users(a)lists.jboss.org>
Date: Thursday, April 30, 2009, 5:38 AM
<div id=yiv198814342><html><span
style="font-family:Verdana;color:#000000;font-size:10pt;"><div> </div>
<div>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:</div>
<div> </div><font
size="2">
<div
align="left"></font><b><font
color="#960000" size="2"><font
color="#960000"
size="2"></b></font></font><font
size="2"><font
size="2"></div>
<div
align="left"></font><b><font
color="#960000" size="2"><font
color="#960000"
size="2">rule</b></font></font><font
size="2"></font><font
color="#008000" size="2"><font
color="#008000"
size="2">"Retract expired
facts"</div>
<div
align="left"></font></font><font
size="2"></div>
<div
align="left"></font><b><font
color="#960000" size="2"><font
color="#960000"
size="2">dialect</b></font></font><font
size="2"></font><font
color="#008000" size="2"><font
color="#008000"
size="2">"mvel"</div>
<div
align="left"></font></font><font
size="2"></div>
<div align="left"></font><font
color="#808000" size="2"><font
color="#808000" size="2">// salience
-5</div>
<div
align="left"></font></font><font
size="2"></div>
<div
align="left"></font><b><font
color="#960000" size="2"><font
color="#960000"
size="2">when</div>
<div
align="left"></b></font></font><font
size="2"></div>
<div align="left">e1 : Event (code ==
</font><font color="#008000"
size="2"><font color="#008000"
size="2">"LOGON"</font></font><font
size="2">, status == </font><font
color="#008000" size="2"><font
color="#008000"
size="2">"ACTIVE"</font></font><font
size="2">)</div>
<div
align="left"></font><b><font
color="#960000" size="2"><font
color="#960000"
size="2">eval</b></font></font><font
size="2"> ((getCurrentTimeStamp ()-
e1.getLongTimeStamp()) > </font><font
size="2">100)</font><font
size="2"></div>
<div
align="left"></font><b><font
color="#960000" size="2"><font
color="#960000"
size="2">then</b></font></font><font
size="2"></div>
<div align="left">System.out.println(
</font><font color="#008000"
size="2"><font color="#008000"
size="2">"Retracting expired event with
Timestamp: "</font></font><font
size="2"> + e1.longTimeStamp ); </div>
<div
align="left"></font><b><font
color="#960000" size="2"><font
color="#960000"
size="2">retract</b></font></font><font
size="2"> (e1);</div>
<div align="left">
<div align="left"></div>
<div align="left"></font><font
color="#960000" size="2"><font
color="#960000" size="2"></div>
<div><strong>end</strong></div>
<div> </div>
<div><font color="#000000">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?</font></div>
<div><font
color="#000000"></font> </div>
<div><font color="#000000">I would
greatly appreciate any ideas.</font></div>
<div> </div>
<div><font
color="#000000">Thanks,</font></div>
<p><font
color="#000000">Ravi.</font></font></font><font
size="2"></div></font></font></span></html>
</div>_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users