[rules-users] Events do not get removed automatically

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


Thanks for the quick answer. But even when adding a temporal constraint 
i get the same result:


rule "choosingSuitTimeout"
when
     $discardCardEvent : GenericEvent(eventName=="discardCard", 
card.equals("c"), $playerIndex : playerIndex)  from entry-point "my stream"
     not (GenericEvent(eventName=="choosingSuit", 
playerIndex==$playerIndex, this after[0s,5s] $discardCardEvent ) from 
entry-point "my stream")
then
     Logger.getLogger("####").info("choosingSuitTimeout FIRED");
end


When adding this rule the example is quite similar to the one listed in 
the documentation ( 
http://docs.jboss.org/drools/release/5.4.0.Final/drools-fusion-docs/html_single/index.html#d0e1370 
).
As such the "discardCard" event should automatically expire afters 5 
secs and be removed making it impossible for the "choosingSuit" rule to 
fire. But still the rule fires...




On 08/14/2012 04:26 PM, Wolfgang Laun wrote:
> It's right here:...
>
> On 14/08/2012, Winfried Umbrath <> wrote:
>> 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.
> ..."due to its temporal constraints"!
>
> There are no such temporal constraints (to be derived from temporal
> operators) in your rules; hence your "events" are just like facts, and
> there is no indication to the Engine that they could or should be
> retracted.
>
> -W
>
>> 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.
>>
>>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


More information about the rules-users mailing list