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

jigna jigna.chhajed at igate.com
Mon Mar 18 05:41:52 EDT 2013


I need to add rule for filtering an event for 30 seconds. 
i.e. The action would be taken once event has occurred for the first time &
then all the events of the same type would be ignored 30 seconds
& action should again take place if  event has occurred anytime after 30
seconds. 
I have tried creating a Throote class for holding thrittle value & timestamp
of firts occurance of events.

Following are the three rules which I am creating for the same.
It works correctly with first two rules, however for triggering third rule,
I need to insert an event which is not '000000A1' 
& then this would give result retarcting ThrottleInfo Object which is
holding timestamp of this event for which throttle period has passed.
How can I make third rule trigger when there is not event of type '000000A1'
after throttle period?

Also is it possible to simplify this & write in single rule using timestamp
or any other features of fusion?



import com.igate.iheal.model.ErrorInfo
import com.igate.iheal.model.ThrottleInfo
import com.igate.iheal.model.process.IHEALProcessModel

declare ErrorInfo
    @role(event)
    @timestamp(errorTimeStamp)
end

rule "Error Rule 1"
    no-loop true
	when
		$Error1:ErrorInfo(errorCode=="000000A1")from entry-point ErrorEntryPoint
		not(exists(ThrottleInfo(errorCode=="000000A1")))
            then 
	            #Passing throttle duration as 30 seconds
	            insert(new
ThrottleInfo("000000A1",30,System.currentTimeMillis()));
		retract($Error1);
		System.out.println("New throttle info instance created");
end

rule "Error Rule 2"
    no-loop true
	when
	             $Error2:ErrorInfo(errorCode=="000000A1") from entry-point
ErrorEntryPoint
		exists(ThrottleInfo(errorCode=="000000A1"))
		$ThrottleError:ThrottleInfo(errorCode=="000000A1")
		eval($ThrottleError.isThrottleCompleted()==true)
		
	then
	             modify($ThrottleError)
{setErrorTimeStamp(System.currentTimeMillis())};
	             retract($Error2);
		System.out.println("Modified throttle info instance");
end

rule "Error Rule 3"
    #no-loop true
	when
		$Error3:ErrorInfo(errorCode!="000000A1") from entry-point ErrorEntryPoint
	             not(ErrorInfo(errorCode=="000000A1"))
		exists(ThrottleInfo(errorCode=="000000A1"))
		$ThrottleError:ThrottleInfo(errorCode=="000000A1")
		eval($ThrottleError.isThrottleCompleted()==true)
             then
	             retract($ThrottleError);
		System.out.println("Delete unused throttle info instance");
end




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


More information about the rules-users mailing list