<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
I'm working on thinking in Drools rules. Right now I'm trying to solve
this:<br>
The rule shall fire if <u>a special event occurs more than 3 times
within 1 hour</u>.<br>
<br>
My <u>first thought of a solution</u> 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?<br>
And global variables must always be initialized from outside the rules
file, don't they?<br>
<br>
Because of these thoughts I've looked for a <u>different solution
without global variables</u>. I came up with:<br>
<br>
<blockquote>function boolean valueExceededLimit(Set<Alarms>
alarmSet) {<br>
//....<br>
}<br>
<br>
rule "more than 3 occurs within 1 hour"<br>
<br>
when<br>
// event #1<br>
$eventA : Value(
eval(parameterValueExceededLimit($eventA.getAlarms())) )<br>
// event #2<br>
$eventB : Value( this after[0ms,1h] $eventA &&<br>
this != $eventA &&<br>
eval(valueExceededLimit($eventB.getAlarms())) )<br>
// event #3<br>
$eventC : Value( this after[0ms,1h] $eventA &&<br>
this != $eventA &&<br>
this != $eventB &&<br>
eval(valueExceededLimit($eventC.getAlarms())) )<br>
// event #4 -> 4 > 3<br>
$eventD : Value( this after[0ms,1h] $eventA &&<br>
this != $eventA &&<br>
this != $eventB &&<br>
this != $eventC &&<br>
eval(valueExceededLimit($eventD.getAlarms())) )<br>
<br>
then<br>
// ... do something ...<br>
<br>
end <br>
</blockquote>
<br>
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.<br>
<br>
<br>
Thanks :)<br>
Tina<br>
</body>
</html>