[rules-users] Insert fact to be used as semaphore

webfrank webfrank at tiscali.it
Tue Nov 5 17:33:44 EST 2013


Hi everybody, I'm new to drools and I would like to solve this simple
situation:

I have a rule which will fire when 3 or more events comes from entry-point
with level > 4 in a 10s window:
rule "Got 3 events"
when
	not Alarm()
	t : Number(intValue > 2) from accumulate (
		e : Event( level > 4) over window:time(10s) from entry-point "queue",
		count(e)
	)
then
	insert(new Alarm());
end

This way if more events comes with level > 4 no more alarms are sent.

I have another rule to retract Alarm object when more than 5 events comes
with level < 6 in a 10s window:

rule "Reset alarm"
when
	a : Alarm()
	c : Number( intValue > 5) from accumulate (
		e : Event( level < 6) over window:time(10s) from entry-point "queue",
		count(e)
	)
then
	 retract(a);
end

The problem is that I got an infinite loop once I retract the Alarm object
and a new is inserted by the first rule.

How could I solve the problem? Probably a different approach but I'm still
learning.



--
View this message in context: http://drools.46999.n3.nabble.com/Insert-fact-to-be-used-as-semaphore-tp4026651.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list