<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>
    &nbsp;&nbsp;&nbsp; @role(event)<br>
    &nbsp;&nbsp;&nbsp; playerIndex : long<br>
    &nbsp;&nbsp;&nbsp; eventName : String<br>
    &nbsp;&nbsp;&nbsp; card : String<br>
    &nbsp;&nbsp;&nbsp; chosenSuit : String<br>
    end<br>
    <br>
    declare Table<br>
    &nbsp;&nbsp;&nbsp; currentPlayerIndex : long<br>
    &nbsp;&nbsp;&nbsp; topCard : String<br>
    end<br>
    <br>
    rule "new table"<br>
    when<br>
    &nbsp;&nbsp;&nbsp; not Table()<br>
    then<br>
    &nbsp;&nbsp;&nbsp; insert(new Table(0,"a"));<br>
    end<br>
    <br>
    rule "discardChoosing"<br>
    when<br>
    &nbsp;&nbsp;&nbsp; $event : GenericEvent(eventName=="discardCard", $playerIndex :
    playerIndex, card.equals("c")) from entry-point "my stream"<br>
    &nbsp;&nbsp;&nbsp; $table : Table(currentPlayerIndex==$playerIndex,
    !topCard.equals("c"))<br>
    then<br>
    &nbsp;&nbsp;&nbsp; Logger.getLogger("####").info("discardChoosing FIRED");<br>
    &nbsp;&nbsp;&nbsp; modify($table) {setTopCard("c")};<br>
    end<br>
    <br>
    rule "choosingSuit"<br>
    &nbsp;&nbsp;&nbsp; no-loop<br>
    when<br>
    &nbsp;&nbsp;&nbsp; $event : GenericEvent(eventName=="choosingSuit", $playerIndex :
    playerIndex, $chosenSuit : chosenSuit) from entry-point "my stream"<br>
    &nbsp;&nbsp;&nbsp; $table : Table(currentPlayerIndex==$playerIndex)<br>
    &nbsp;&nbsp;&nbsp; $discardCardEvent : GenericEvent(eventName=="discardCard",
    playerIndex==$playerIndex, card.equals("c"))&nbsp; from entry-point "my
    stream"<br>
    then<br>
    &nbsp;&nbsp;&nbsp; Logger.getLogger("####").info("choosingSuit FIRED");<br>
    &nbsp;&nbsp;&nbsp; modify($table)
    {setCurrentPlayerIndex($table.getCurrentPlayerIndex() + 1)};<br>
    end<br>
    <br>
    rule "previousPlayer"<br>
    when<br>
    &nbsp;&nbsp;&nbsp; $event : GenericEvent(eventName=="previousPlayer") from
    entry-point "my stream"<br>
    &nbsp;&nbsp;&nbsp; $table : Table()<br>
    then<br>
    &nbsp;&nbsp;&nbsp; Logger.getLogger("####").info("previousPlayer FIRED");<br>
    &nbsp;&nbsp;&nbsp; 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>