[rules-users] Drools Activation Group

Wolfgang Laun wolfgang.laun at gmail.com
Wed Nov 30 01:49:27 EST 2011


You misunderstood the term "fire", which is commonly used to say that
a rule's consequence is executed. This means that you can't use
activation-group to achieve what you want.

What you mean when you write "fire" is the rule condition's
evaluation. This is not a process that can be controlled easily.
Moreover, it (generally) isn't a process that happens in one go:
evaluation begins with the insertion (or update or retraction) of a
fact, may be halted due to the absences of some other fact, and
continue when that fact appears, and so on. The general advice is to
write your conditions so that evaluation is safe in any case.

In your case, "safe" means that the DB lookup must not be done for
empty keys. To do so, omit the activation-group and write your second
rule like so:

rule "r2"
  when
     SomeObject($s: someStringKey)
     eval( ! sEmpty($s) && checkWithDB($s) )
  then
      log("doSomething");
end

-W

2011/11/29 Java Bean <freejava3 at gmail.com>:
> Hello Drools Experts,
>
> I have a question on activation group and trying to understand the
> mechanism.
>
> I have the following rules in a .drl file :
>
> import function com.test.utils.StringUtil.isEmpty;
> import function com.test.utils.Logger.log;
>
> rule "r1"
>   salience 10
>   activation-group "fireOnlyOnce"
>   when
>      SomeObject($s: someStringKey)
>      eval(isEmpty($s) // static java method imported as function
>   then
>       log("doSomething");
> end
>
> rule "r2"
>   activation-group "fireOnlyOnce"
>   when
>      SomeObject($s: someStringKey)
>      eval(checkWithDB($s) // Make a call to the DB to validate
> someStringKeyis valid
>   then
>       log("doSomething");
> end
>
> In "r1" I am checking for 'someStringKey' is not null or empty. In "r2" , I
> am making a call to the DB to check 'someStringKey' is a valid id. During
> the debug, I found out that both "r1" and "r2" is fired but only one
> consequence is executed depending on the outcome of the r1. I want "r2" to
> fire only when "r1" evaluates to false. How can I achieve this in Drools?
>
> Thanks for your time and appreciate your help.
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>




More information about the rules-users mailing list