2010/8/5 Tina Vießmann <span dir="ltr">&lt;<a href="mailto:tviessmann@stud.hs-bremen.de">tviessmann@stud.hs-bremen.de</a>&gt;</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&#39;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&#39;t expect it to be,
but why not ask. ;))<br></div></blockquote><div><br>The DRL language provides &quot;declare&quot; (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 &quot;class Watcher&quot;. (If you use declare, you&#39;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  &amp;&amp;<br>
 
//                                   this != $eventA  &amp;&amp;     
### set includes Watcher.what<br>
                                  
 eval(valueExceededLimit($eventB.getAlarms()) &amp;&amp; !
$set.contains( this ) ) )</blockquote>
I&#39;m sorry, could you explain to me the part of $eventB in sentences,
please? I&#39;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&#39;s $set does not contain this Value<br>
then...<br><br>The line I commented out isn&#39;t necessary as I propose to add the very 1st event tied to the Watcher to this Watcher&#39;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&#39;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&lt;Value&gt; valueSet = new HashSet&lt;Value&gt;();<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  &amp;&amp;<br>
 
//                                   this != $eventA  &amp;&amp;     
### set includes Watcher.what<br>
                                  
 eval(valueExceededLimit($eventB.getAlarms()) &amp;&amp; !
$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 &gt; 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&#39;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">&lt;<a href="mailto:tviessmann@stud.hs-bremen.de" target="_blank">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&#39;m working on thinking in Drools rules. Right now I&#39;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&#39;t it? And global variables are not to be used to
frequently, aren&#39;t they?<br>
And global variables must always be initialized from outside the rules
file, don&#39;t they?<br>
    <br>
Because of these thoughts I&#39;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>
   //....<br>
}<br>
      <br>
rule &quot;more than 3 occurs within 1 hour&quot;<br>
      <br>
    when<br>
        // event #1<br>
        $eventA : Value(
eval(parameterValueExceededLimit($eventA.getAlarms())) )<br>
        // event #2<br>
        $eventB : Value( this after[0ms,1h] $eventA  &amp;&amp;<br>
                                    this != $eventA  &amp;&amp;<br>
                                  
 eval(valueExceededLimit($eventB.getAlarms())) )<br>
        // event #3<br>
        $eventC : Value( this after[0ms,1h] $eventA  &amp;&amp;<br>
                                    this != $eventA  &amp;&amp;<br>
                                    this != $eventB  &amp;&amp;<br>
                                  
 eval(valueExceededLimit($eventC.getAlarms())) )<br>
        // event #4  -&gt;  4 &gt; 3<br>
        $eventD : Value( this after[0ms,1h] $eventA  &amp;&amp;<br>
                                    this != $eventA  &amp;&amp;<br>
                                    this != $eventB  &amp;&amp;<br>
                                    this != $eventC  &amp;&amp;<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>