<!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.&nbsp; :)<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>
&nbsp;$watcher : Watcher( $eventA : what, $set : valueSet )<br>
&nbsp;$eventB : Value( this after[0ms,1h] $eventA&nbsp; &amp;&amp;<br>
&nbsp;
// &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; this != $eventA&nbsp; &amp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
### set includes Watcher.what<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;eval(valueExceededLimit($eventB.getAlarms()) &amp;&amp; !
$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>
&nbsp;&nbsp; Value what;<br>
&nbsp;&nbsp; int count = 1;<br>
&nbsp;&nbsp; Set&lt;Value&gt; valueSet = new HashSet&lt;Value&gt;();<br>
&nbsp;&nbsp; Watcher( Value first ){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueSet.add( what = first );<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp; //...<br>
}<br>
  <br>
And now the rules:<br>
  <br>
rule attachWatcher<br>
when<br>
&nbsp; $event : Value(
eval(parameterValueExceededLimit($eventA.getAlarms())) )<br>
&nbsp; not( Watcher( what == $event ) )<br>
then<br>
&nbsp; insert( new Watcher( $event ) );<br>
end<br>
  <br>
rule addEvent<br>
when<br>
&nbsp;$watcher : Watcher( $eventA : what, $set : valueSet )<br>
&nbsp;$eventB : Value( this after[0ms,1h] $eventA&nbsp; &amp;&amp;<br>
&nbsp;
// &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; this != $eventA&nbsp; &amp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
### set includes Watcher.what<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;eval(valueExceededLimit($eventB.getAlarms()) &amp;&amp; !
$set.contains( this ) ) )<br>
then<br>
&nbsp; modify( $watcher ){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setValueList( $watcher.getValueSet().add( $eventB ),<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setCount( $watcher.getCount() + 1 )<br>
&nbsp; }<br>
end<br>
  <br>
rule testLimit<br>
when<br>
&nbsp;&nbsp; $watcher : Watcher( count &gt; Limit )<br>
then<br>
&nbsp; // raise hell,<br>
&nbsp; // 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&szlig;mann <span dir="ltr">&lt;<a
 moz-do-not-send="true" href="mailto:tviessmann@stud.hs-bremen.de">tviessmann@stud.hs-bremen.de</a>&gt;</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>
&nbsp; 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&lt;Alarms&gt;
alarmSet) {<br>
&nbsp;&nbsp; //....<br>
}<br>
      <br>
rule "more than 3 occurs within 1 hour"<br>
      <br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// event #1<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$eventA : Value(
eval(parameterValueExceededLimit($eventA.getAlarms())) )<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// event #2<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$eventB : Value( this after[0ms,1h] $eventA&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this != $eventA&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;eval(valueExceededLimit($eventB.getAlarms())) )<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// event #3<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$eventC : Value( this after[0ms,1h] $eventA&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this != $eventA&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this != $eventB&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;eval(valueExceededLimit($eventC.getAlarms())) )<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// event #4&nbsp; -&gt;&nbsp; 4 &gt; 3<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$eventD : Value( this after[0ms,1h] $eventA&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this != $eventA&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this != $eventB&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this != $eventC&nbsp; &amp;&amp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;eval(valueExceededLimit($eventD.getAlarms())) )<br>
      <br>
&nbsp;&nbsp;&nbsp; then<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // ... 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>