2010/8/5 Tina Vießmann <tviessmann@stud.hs-bremen.de>
Thank you for this approach, Wolfgang. That sounds great.  :)
I just have some further question about your solution.

#1
I'm thinking about an approach without the need modifying things outside the drl file. Is something like that doable?
Because I have to create the watcher class? (I don't expect it to be, but why not ask. ;))

The DRL language provides "declare" (see Section 4.7 in the Expert manual). Metadata is described in the Fusion manual.

 

#2
(What and count are somewhat redundant, but this avoids clumsy patterns.)
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)?

No! See the Java snippet "class Watcher". (If you use declare, you'll have to do the initializations after creation.)
 

#3
rule addEvent
when
 $watcher : Watcher( $eventA : what, $set : valueSet )
 $eventB : Value( this after[0ms,1h] $eventA  &&
  //                                   this != $eventA  &&      ### set includes Watcher.what
                                    eval(valueExceededLimit($eventB.getAlarms()) && ! $set.contains( this ) ) )
I'm sorry, could you explain to me the part of $eventB in sentences, please? I've got confused by the comments... :(

If there is
a Watcher watching $eventA and with a set of related events $set,
and
a Value less than 1hr later than $eventA and with more alarms than limit and Watcher's $set does not contain this Value
then...

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.



Thank you very much! :)

You're welcome.
-W
 
Tina



Basic idea: associate a Watcher with each event.

class Watcher {
   Value what;
   int count = 1;
   Set<Value> valueSet = new HashSet<Value>();
   Watcher( Value first ){
      valueSet.add( what = first );
   }
   //...
}

And now the rules:

rule attachWatcher
when
  $event : Value( eval(parameterValueExceededLimit($eventA.getAlarms())) )
  not( Watcher( what == $event ) )
then
  insert( new Watcher( $event ) );
end

rule addEvent
when
 $watcher : Watcher( $eventA : what, $set : valueSet )
 $eventB : Value( this after[0ms,1h] $eventA  &&
  //                                   this != $eventA  &&      ### set includes Watcher.what
                                    eval(valueExceededLimit($eventB.getAlarms()) && ! $set.contains( this ) ) )
then
  modify( $watcher ){
      setValueList( $watcher.getValueSet().add( $eventB ),
      setCount( $watcher.getCount() + 1 )
  }
end

rule testLimit
when
   $watcher : Watcher( count > Limit )
then
  // raise hell,
  // probably: get rid of all in $watcher.set, and $watcher
end

(What and count are somewhat redundant, but this avoids clumsy patterns.)

Watcher should be declared as Event, with @expires, so they'll disappear with the (primary) Event each one is watching.

Cheers
-W


2010/8/5 Tina Vießmann <tviessmann@stud.hs-bremen.de>
Hi,

I'm working on thinking in Drools rules. Right now I'm trying to solve this:
  The rule shall fire if a special event occurs more than 3 times within 1 hour.

My first thought of a solution 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?
And global variables must always be initialized from outside the rules file, don't they?

Because of these thoughts I've looked for a different solution without global variables. I came up with:

function boolean valueExceededLimit(Set<Alarms> alarmSet) {
   //....
}

rule "more than 3 occurs within 1 hour"

    when
        // event #1
        $eventA : Value( eval(parameterValueExceededLimit($eventA.getAlarms())) )
        // event #2
        $eventB : Value( this after[0ms,1h] $eventA  &&
                                    this != $eventA  &&
                                    eval(valueExceededLimit($eventB.getAlarms())) )
        // event #3
        $eventC : Value( this after[0ms,1h] $eventA  &&
                                    this != $eventA  &&
                                    this != $eventB  &&
                                    eval(valueExceededLimit($eventC.getAlarms())) )
        // event #4  ->  4 > 3
        $eventD : Value( this after[0ms,1h] $eventA  &&
                                    this != $eventA  &&
                                    this != $eventB  &&
                                    this != $eventC  &&
                                    eval(valueExceededLimit($eventD.getAlarms())) )

    then
        // ... do something ...

end

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.


Thanks :)
Tina

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users