2010/8/5 Tina Vießmann <span dir="ltr"><<a href="mailto:tviessmann@stud.hs-bremen.de">tviessmann@stud.hs-bremen.de</a>></span><br><div class="gmail_quote"><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">
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></div></blockquote><div><br>The DRL language provides "declare" (see Section 4.7 in the Expert manual). Metadata is described in the Fusion manual.<br><br> </div><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">
<br>
#2<br>
<blockquote 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></div></blockquote><div><br>No! See the Java snippet "class Watcher". (If you use declare, you'll have to do the initializations after creation.)<br>
</div><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">
<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></div></blockquote><div><br>If there is <br>a Watcher watching $eventA and with a set of related events $set,<br>and<br>a Value less than 1hr later than $eventA and with more alarms than limit and Watcher's $set does not contain this Value<br>
then...<br><br>The line I commented out isn't necessary as I propose to add the very 1st event tied to the Watcher to this Watcher's list.<br><br></div><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">
<br>
<br>
Thank you very much! :)<br></div></blockquote><div><br>You're welcome.<br>-W<br> </div><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">
Tina<br>
<br>
<br>
<br>
<blockquote 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 href="mailto:tviessmann@stud.hs-bremen.de" target="_blank">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 href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a 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><fieldset></fieldset>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a 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>