You'll need one rule for detecting the first occurrence, another rule
for ignoring successive events and a third one to remove the "flag"
event the first rule has inserted and that's used in the second rule.
declare ErrorFlag
String errorCode
end
rule "first time"
when
$ei: ErrorInfo($errorCode: errorCode)
not ErrorFlag( errorCode == $errorCode )
then
insert( new ErrorFlag( $errorCode ) );
// action
retract( $ei );
end
rule "repeats"
when
$ei: ErrorInfo($errorCode: errorCode)
ErrorFlag( errorCode == $errorCode )
then
retract( $ei );
end
rule "remove ErrorFlag"
timer ( int: 30s )
when
$ef: ErrorFlag()
then
retract( $ef );
end
-W
On 18/03/2013, jigna <jigna.chhajed(a)igate.com> wrote:
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-me...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users