[rules-users] Fact insertion & retraction in working memory

jigna jigna.chhajed at igate.com
Wed Apr 3 07:39:19 EDT 2013


I have tried using @expire feature for Errorflag, which I expect to get
expired after 30s, instead of using timer for a rule.
it seems to be working correctly for a single rule.

declare ErrorFlag 
	@expire(30s)
  errorCode : String
end


rule "first time" 
when 
   $Error1:ErrorInfo(errorCode=="000000A1")from entry-point ErrorEntryPoint 
   not ErrorFlag( errorCode == "000000A1" ) 
then 
   insert( new ErrorFlag( "000000A1" ) ); 
   // action 
   retract( $Error1 ); 
end

I then needed to use this approach for mutiple rules, hence I declared the
string field in this Errorflag for holding the rule name.

declare ErrorFlag 
	@expire(30s)
  errorRuleFlag : String
end

rule "first_Rule" 
when 
   $Error1:ErrorInfo(errorCode=="000000A1")from entry-point ErrorEntryPoint 
   not ErrorFlag( errorRuleFlag == "first_Rule" ) 
then 
   insert( new ErrorFlag( "first_Rule" ) ); 
   // action 
   retract( $Error1 ); 
end

rule "Second_Rule" 
when 
   $Error1:ErrorInfo(errorCode=="000000A2")from entry-point ErrorEntryPoint 
   not ErrorFlag( errorRuleFlag == "Second_Rule" ) 
then 
   insert( new ErrorFlag( "Second_Rule" ) ); 
   // action 
   retract( $Error1 ); 
end

I expected that it would create different instance of ErrorFlag & counting
of 30s for each of instance would start when it was 'new' created in Then
part.
However, with this approach only first rule worked.

I ended up declaring individual errorflag for each of the rule.
I am trying to understand it's (@expire) actual working & what did I miss on
when I expecetd it work with single declaration & mutiple instances?



--
View this message in context: http://drools.46999.n3.nabble.com/Fact-insertion-retraction-in-working-memory-tp4022850p4023194.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list