<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi guys,<br>
<br>
the drools fusion documentation states that <br>
<br>
"<a id="d0e1340">One of the benefits of running the engine in STREAM
mode is that the engine can detect when an event can no longer
match any rule due to its temporal constraints. When that happens,
the engine can safely retract the event from the session without
side effects and release any resources used by that event.</a>"<br>
<br>
I have a hard time understanding why my events do not get removed.
In the following example I have following rules running in stream
mode:<br>
<br>
----------------------------------------------------------------------------------------------------------------------------<br>
package rules<br>
<br>
import java.util.logging.Logger<br>
<br>
declare GenericEvent<br>
@role(event)<br>
playerIndex : long<br>
eventName : String<br>
card : String<br>
chosenSuit : String<br>
end<br>
<br>
declare Table<br>
currentPlayerIndex : long<br>
topCard : String<br>
end<br>
<br>
rule "new table"<br>
when<br>
not Table()<br>
then<br>
insert(new Table(0,"a"));<br>
end<br>
<br>
rule "discardChoosing"<br>
when<br>
$event : GenericEvent(eventName=="discardCard", $playerIndex :
playerIndex, card.equals("c")) from entry-point "my stream"<br>
$table : Table(currentPlayerIndex==$playerIndex,
!topCard.equals("c"))<br>
then<br>
Logger.getLogger("####").info("discardChoosing FIRED");<br>
modify($table) {setTopCard("c")};<br>
end<br>
<br>
rule "choosingSuit"<br>
no-loop<br>
when<br>
$event : GenericEvent(eventName=="choosingSuit", $playerIndex :
playerIndex, $chosenSuit : chosenSuit) from entry-point "my stream"<br>
$table : Table(currentPlayerIndex==$playerIndex)<br>
$discardCardEvent : GenericEvent(eventName=="discardCard",
playerIndex==$playerIndex, card.equals("c")) from entry-point "my
stream"<br>
then<br>
Logger.getLogger("####").info("choosingSuit FIRED");<br>
modify($table)
{setCurrentPlayerIndex($table.getCurrentPlayerIndex() + 1)};<br>
end<br>
<br>
rule "previousPlayer"<br>
when<br>
$event : GenericEvent(eventName=="previousPlayer") from
entry-point "my stream"<br>
$table : Table()<br>
then<br>
Logger.getLogger("####").info("previousPlayer FIRED");<br>
modify($table)
{setCurrentPlayerIndex($table.getCurrentPlayerIndex() - 1)};<br>
end<br>
----------------------------------------------------------------------------------------------------------------------------<br>
<br>
<br>
I would expect after inserting "discardCard" followed by
"choosingSuit" event, both should be retracted as their conditions
do not evaluate to true anymore. But even after sleeping a couple of
seconds, the rule "choosingSuit" fires again, which means to me the
events are still in working memory. Here is the log output:<br>
<br>
<br>
inserting GenericEvent( playerIndex=0, eventName=discardCard,
card=c, chosenSuit=null )<br>
INFO: discardChoosing FIRED<br>
INFO: choosingSuit FIRED<br>
inserting GenericEvent( playerIndex=0, eventName=choosingSuit,
card=null, chosenSuit=HEARTS )<br>
Sleeping 9 seconds...<br>
Sleeping done. Printing facts:<br>
Fact handle: [fact 0:2:1690464956:1690464956:5:DEFAULT:Table(
currentPlayerIndex=1, topCard=c )]<br>
inserting GenericEvent( playerIndex=0, eventName=previousPlayer,
card=null, chosenSuit=null )<br>
INFO: previousPlayer FIRED<br>
INFO: choosingSuit FIRED<br>
INFO: previousPlayer FIRED<br>
INFO: choosingSuit FIRED<br>
INFO: previousPlayer FIRED<br>
INFO: choosingSuit FIRED<br>
INFO: previousPlayer FIRED<br>
INFO: choosingSuit FIRED<br>
INFO: previousPlayer FIRED<br>
...<br>
<br>
<br>
I'm running Drools 5.4 and inserting/executing in this way:<br>
List cmds = new ArrayList();<br>
cmds.add(CommandFactory.newInsert(discard, "event", false, "my
stream"));<br>
cmds.add(CommandFactory.newFireAllRules(20));<br>
System.out.println("inserting " + discard);<br>
ksession.execute(CommandFactory.newBatchExecution(cmds));<br>
<br>
<br>
Any help is highly appreciated.<br>
<br>
</body>
</html>