It seems that a full definition of the semantics of @expires is still missing from the Fusion manual.

"After that time, assuming no rule still needs the event, the engine will expire and remove the event from the session automatically." (Emphasis by me.)

So, when does a rule "need an event"? This is a very iffy definition.

Consider:
   when
      Event()
   then
This rule certainly "needs" an Event fact, but does it still need it after the first firing? Not unless Event() is modified, which might happen elsewhere.

In the case of a timer() being added to a rule, there is a similar dilemma. A rule like
  rule
    timer(int: 5s)
  when
    Event()
  then
does and, simultaneously does not, "need" an Event() fact. If Event() is retracted after less than 5s, the rule should not fire - so the rule does not "need" the fact. OTOH, its timed firing depends on the presence of an Event() - so the rule "needs" the fact.

You can easily thwart the algorithm that determines "is needed":

rule "check timer attribute"
    timer (int: 5s 1s)
when
    $alert : Object( eval($alert instanceof Alert) ) from entry-point "EventStream"
then
     System.out.println( ((Alert)$alert).getId() +
                        " time: " + (Calendar.getInstance().getTimeInMillis()));
end

-W



On 28 November 2011 07:32, prashant.badhe <prashant.badhe@gmail.com> wrote:
Here is the complete rule that we trying out with 'timer' & '@expires' :

~~~~~~~~~~~~~
package xyz;

import abc.Alert;
import abc.CResult;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;
import java.util.Calendar;
import java.util.Timer;

declare Alert
       @role( event )
       @expires( 30s )
end

declare CResult
       @role( event )
       @expires( 30s )
end

rule "check timer attribute"
       agenda-group "xyz"
       auto-focus true
       no-loop
       salience 140
              timer (int: 5s)
       //duration ( 5s )

       when
               $alert : Alert( $alertId:id ) from entry-point "EventStream"
       then
               System.out.println("Inside RHS...[alert=" + $alert.getId() + "]
[Time: " + (Calendar.getInstance().getTimeInMillis()));

end
~~~~~~~~~~~~~

We are trying this out on Drools 5.3.0 stateful knowledge session operating
in stream mode.

The above rule is not firing on inserting Alert fact. If I comment line
'timer (int: 5s 5s)' then it starts firing.

About the @expires, our assumption is Alert fact inserted is not expiring,
as the count returned by getFactCount() on WM entrypoint object is returned
as 1 even after a thread sleep of more than 60 seconds post the rule firing.

Please correct us if this assumption is wrong or something more is required
for @expires to work. Similarly for timer(int: 5s) let us know what is
wrong.

Does the facts that are expired remains in WM but are not evaluated for any
new facts/rules inserted in WM OR they are removed from WM?

-Prashant




--
View this message in context: http://drools.46999.n3.nabble.com/rules-users-duration-attribute-other-rule-language-features-issue-tp3536857p3541469.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users