[rules-users] Events do not get removed automatically

Winfried Umbrath wumb at gameduell.de
Tue Aug 14 10:12:19 EDT 2012


Hi guys,

the drools fusion documentation states that

"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."

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:

----------------------------------------------------------------------------------------------------------------------------
package rules

import java.util.logging.Logger

declare GenericEvent
     @role(event)
     playerIndex : long
     eventName : String
     card : String
     chosenSuit : String
end

declare Table
     currentPlayerIndex : long
     topCard : String
end

rule "new table"
when
     not Table()
then
     insert(new Table(0,"a"));
end

rule "discardChoosing"
when
     $event : GenericEvent(eventName=="discardCard", $playerIndex : 
playerIndex, card.equals("c")) from entry-point "my stream"
     $table : Table(currentPlayerIndex==$playerIndex, !topCard.equals("c"))
then
     Logger.getLogger("####").info("discardChoosing FIRED");
     modify($table) {setTopCard("c")};
end

rule "choosingSuit"
     no-loop
when
     $event : GenericEvent(eventName=="choosingSuit", $playerIndex : 
playerIndex, $chosenSuit : chosenSuit) from entry-point "my stream"
     $table : Table(currentPlayerIndex==$playerIndex)
     $discardCardEvent : GenericEvent(eventName=="discardCard", 
playerIndex==$playerIndex, card.equals("c"))  from entry-point "my stream"
then
     Logger.getLogger("####").info("choosingSuit FIRED");
     modify($table) 
{setCurrentPlayerIndex($table.getCurrentPlayerIndex() + 1)};
end

rule "previousPlayer"
when
     $event : GenericEvent(eventName=="previousPlayer") from entry-point 
"my stream"
     $table : Table()
then
     Logger.getLogger("####").info("previousPlayer FIRED");
     modify($table) 
{setCurrentPlayerIndex($table.getCurrentPlayerIndex() - 1)};
end
----------------------------------------------------------------------------------------------------------------------------


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:


inserting GenericEvent( playerIndex=0, eventName=discardCard, card=c, 
chosenSuit=null )
INFO: discardChoosing FIRED
INFO: choosingSuit FIRED
inserting GenericEvent( playerIndex=0, eventName=choosingSuit, 
card=null, chosenSuit=HEARTS )
Sleeping 9 seconds...
Sleeping done. Printing facts:
Fact handle: [fact 0:2:1690464956:1690464956:5:DEFAULT:Table( 
currentPlayerIndex=1, topCard=c )]
inserting GenericEvent( playerIndex=0, eventName=previousPlayer, 
card=null, chosenSuit=null )
INFO: previousPlayer FIRED
INFO: choosingSuit FIRED
INFO: previousPlayer FIRED
INFO: choosingSuit FIRED
INFO: previousPlayer FIRED
INFO: choosingSuit FIRED
INFO: previousPlayer FIRED
INFO: choosingSuit FIRED
INFO: previousPlayer FIRED
...


I'm running Drools 5.4 and inserting/executing in this way:
List cmds = new ArrayList();
cmds.add(CommandFactory.newInsert(discard, "event", false, "my stream"));
cmds.add(CommandFactory.newFireAllRules(20));
System.out.println("inserting " + discard);
ksession.execute(CommandFactory.newBatchExecution(cmds));


Any help is highly appreciated.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120814/1162d101/attachment.html 


More information about the rules-users mailing list