[rules-users] Understanding agenda-group (doesn't work as documented in book or docs)

Edson Tirelli ed.tirelli at gmail.com
Thu Jan 21 14:03:20 EST 2010


   Hehe, ok, lets try to clarify then. In your example, you have 2 rules.
Assuming your are *not* using any kind of grouping, when you insert the
message with status HELLO, then engine knows that only the first rule is
eligible to execute, and so the engine fires it. The consequence of rule 1
changes the message status, making rule 2 eligible and so it fires in
sequence. That is called rule chaining, and that is how forward chaining
engines like drools work and do inference. So, in that simplistic example,
if you go simple (as in not using groups), the engine is smart enough to
figure out what to do.

   Now, real use cases can be modeled like that and implemented using a few
tricks like control facts and it will work. Although, that would miss the
point of being a declarative platform for behavior modeling. So, Drools
introduced a few ways to coordinate the execution of rule groups, namely
agenda-groups, ruleflow-groups and activation-groups. Whenever you
*explicitly* set one of these attributes in the rule, you are telling the
engine:

"- I know what I am doing. Do as you are told and don't try to be smart."

   That is why, the setFocus() methods define the order in which elements
are placed into the stack and it will execute them in the given FIFO (stack
semantic) order, or not execute them at all. So:

* agenda-groups: uses stack semantics, as you quoted in your first e-mail.
The stack starts with the MAIN agenda-group, and every time you call
setFocus() from the application code *or* from a rules consequence *or* a
rule with auto-focus true is activated, it will push that group on top of
the stack. This is extremely useful for cases like exception handling (not
*java* exception, more like "exceptional cases") among other situations. It
can also emulate "sub-procedure" semantics, where a given reasoning cycle is
paused while another reasoning cycle is called and when that finishes, it
comes back to he original reasoning cycle and continues.

* ruleflow-group: uses workflow semantics, where you define a sequential
flow/process and each step is executed in sequence. This is a much easier
way to model sequencing, and specially useful for process-like or phased
execution. The modeling is also visual, making it easier for users to deal
with.

* activation-group: it tells the engine that the rules in that group are
mutually exclusive and whenever one of them fires, it automatically cancels
the activations of all other rules in the same group. I personally don't
like this one and always avoid it when authoring rules, but it is there for
those that want to use the feature.

    Whenever you use any of these controls, you are telling the engine to
comply with their semantics. That is why I thought your comment on
"jeopardizing developer intentions" was funny, but I meant no disrespect.
One thing is to admit you are not understanding something. I different thing
is to criticize something you don't understand. I always tell users to start
simple: try letting the engine figure out which rules to fire and which
order. If that does not work for you, then look for alternatives. One can do
extremely sophisticated models by mixing the above groups in the same rule,
but you need to know what you are doing or things might not result in the
way you expected them to be.

    Edson

2010/1/21 Pritam <infinity2heaven at gmail.com>

>
> If you're curious how a Stack is implemented in Java, C or C++, have a look
> at the method names: push, pop etc., There's a reason why the names are
> push, pop and not setXXX.
>
> It's not a good design where an operation with a method signature that
> resembles a standard javabean accessor like setXXX hides a stack
> implementation behind it, without documentation. Drools api doesn't even
> have a javadocs for
> http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/apidocs/index.html
> AgendaGroup  setFocus and clear().
>
> I'm curious about the ordering based on groups, since I've built a html
> render engine that defers a part of the render process to a rules provider
> and the input the rules provider (drools) is a URL which abstracts
> different
> sections, sub sections and page. I need the rules to be applied to each of
> this separately and override it as well.
>
> If you're interested to solve a real problem, I'd appreciate.
>
> --
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20100121/87dbced9/attachment.html 


More information about the rules-users mailing list