Hi,
I'm working on thinking in Drools rules. Right now I'm trying to solve
this:
The rule shall fire if a special event occurs more than 3 times
within 1 hour.
My first thought of a solution was to count the count the
detected events using a counter. But the counter has to be a global
variable, hasn't it? And global variables are not to be used to
frequently, aren't they?
And global variables must always be initialized from outside the rules
file, don't they?
Because of these thoughts I've looked for a different solution
without global variables. I came up with:
function boolean valueExceededLimit(Set<Alarms>
alarmSet) {
//....
}
rule "more than 3 occurs within 1 hour"
when
// event #1
$eventA : Value(
eval(parameterValueExceededLimit($eventA.getAlarms())) )
// event #2
$eventB : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
eval(valueExceededLimit($eventB.getAlarms())) )
// event #3
$eventC : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
this != $eventB &&
eval(valueExceededLimit($eventC.getAlarms())) )
// event #4 -> 4 > 3
$eventD : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
this != $eventB &&
this != $eventC &&
eval(valueExceededLimit($eventD.getAlarms())) )
then
// ... do something ...
end
More than 3 is kind of a doable task. But I think of this solution as
heavy in case its needed to detect a larger number of events. I would
be thankful for other approaches to the problem.
Thanks :)
Tina