<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thank you for this approach, Wolfgang. That sounds great. :)<br>
I just have some further question about your solution.<br>
<br>
#1<br>
I'm thinking about an approach without the need modifying things
outside the drl file. Is something like that doable?<br>
Because I have to create the watcher class? (I don't expect it to be,
but why not ask. ;))<br>
<br>
#2<br>
<blockquote
cite="mid:AANLkTikRRctnZSYRo49GrmfP9Xsg2WqybtULYP1bO4M4@mail.gmail.com"
type="cite">(What and count are somewhat redundant, but this avoids
clumsy patterns.)<br>
</blockquote>
Am I right that what and count have to be defined as global variables
and initialized using setGlobal() (from a part of the java application)?<br>
<br>
#3<br>
<blockquote type="cite">rule addEvent<br>
when<br>
$watcher : Watcher( $eventA : what, $set : valueSet )<br>
$eventB : Value( this after[0ms,1h] $eventA &&<br>
// this != $eventA &&
### set includes Watcher.what<br>
eval(valueExceededLimit($eventB.getAlarms()) && !
$set.contains( this ) ) )</blockquote>
I'm sorry, could you explain to me the part of $eventB in sentences,
please? I've got confused by the comments... :(<br>
<br>
<br>
Thank you very much! :)<br>
Tina<br>
<br>
<br>
<br>
<blockquote
cite="mid:AANLkTikRRctnZSYRo49GrmfP9Xsg2WqybtULYP1bO4M4@mail.gmail.com"
type="cite">Basic idea: associate a Watcher with each event.<br>
<br>
class Watcher {<br>
Value what;<br>
int count = 1;<br>
Set<Value> valueSet = new HashSet<Value>();<br>
Watcher( Value first ){<br>
valueSet.add( what = first );<br>
}<br>
//...<br>
}<br>
<br>
And now the rules:<br>
<br>
rule attachWatcher<br>
when<br>
$event : Value(
eval(parameterValueExceededLimit($eventA.getAlarms())) )<br>
not( Watcher( what == $event ) )<br>
then<br>
insert( new Watcher( $event ) );<br>
end<br>
<br>
rule addEvent<br>
when<br>
$watcher : Watcher( $eventA : what, $set : valueSet )<br>
$eventB : Value( this after[0ms,1h] $eventA &&<br>
// this != $eventA &&
### set includes Watcher.what<br>
eval(valueExceededLimit($eventB.getAlarms()) && !
$set.contains( this ) ) )<br>
then<br>
modify( $watcher ){<br>
setValueList( $watcher.getValueSet().add( $eventB ),<br>
setCount( $watcher.getCount() + 1 )<br>
}<br>
end<br>
<br>
rule testLimit<br>
when<br>
$watcher : Watcher( count > Limit )<br>
then<br>
// raise hell,<br>
// probably: get rid of all in $watcher.set, and $watcher<br>
end<br>
<br>
(What and count are somewhat redundant, but this avoids clumsy
patterns.)<br>
<br>
Watcher should be declared as Event, with @expires, so they'll
disappear with the (primary) Event each one is watching.<br>
<br>
Cheers<br>
-W<br>
<br>
<br>
<div class="gmail_quote">2010/8/5 Tina Vießmann <span dir="ltr"><<a
moz-do-not-send="true" href="mailto:tviessmann@stud.hs-bremen.de">tviessmann@stud.hs-bremen.de</a>></span><br>
<blockquote class="gmail_quote"
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div 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>
</div>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a moz-do-not-send="true" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a moz-do-not-send="true"
href="https://lists.jboss.org/mailman/listinfo/rules-users"
target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br>
</blockquote>
</div>
<br>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
</body>
</html>