Thank you for your fast reply.
First:
I don't want to dictate an execution order in the style of A->B->C. I want
that my agenda-groups will get focused in a predictable manner if there is a
conflict between auto-focused rules. To use the order in which they appear
in the drl-file seems to be a bit risky: this feature is not documented, it
is inconvenient to use and I can't count on it to continue working the same
way in a future version. As salience already exists, I don't see why it
couldn't be used for this purpose also. To me it would seem logical.
Second:
I must have written the second part somehow unclear. I want that the rule
that grabs the focus for the group gets fired even if it has lock-on-active
set to true. Now it just grabs the focus but doesn't fire. Using the
following example to clarify:
rule "ruleA"
agenda-group "a group"
auto-focus true
lock-on-active true
when
Fact(name="fact1")
then
System.out.println("ruleA fired");
end
rule "ruleB"
agenda-group "a group"
no-loop true
when
f : Fact(name=="fact1")
then
System.out.println("ruleB fired");
f.setValue("new value");
update(f);
end
Now the printed output from this is
ruleB fired
even though I would expect it to be
ruleA fired
ruleB fired
If I would put the no-loop instead of lock-on-active to ruleA, then the two
rules would get locked in an infinite dog-chasing-the-tail kinda situation.
Hopefully I managed to clarify my point.
Olli
On Tue, Dec 29, 2009 at 12:23 AM, Greg Barton <greg_barton(a)yahoo.com> wrote:
First:
According to the drools docs: "Only rules in the agenda group that has
acquired the focus are allowed to fire."
Salience is an inter-rule directive, affecting the execution order between
two rules that are currently eligible to fire. Since only one agenda-group
can be active at once, by definition the saliences of rules in different
groups have no bearing on each other.
If you want to dictate the execution order of groups of rules I'd suggest
using ruleflows and ruleflow-group. With those you have far more nuance and
control than just simple salience. Because of that I doubt there would be
any addition of an "agenda group salience" feature, unless you write it.
Second:
Did you intend to add lock-on-active to rule3? You seem to imply that. If
so, and if you intend rule3 to be default salience, it makes sense that
rule3 would fire and not rule2. rule3 fires first because of it's higher
salience, and then the activation of rule2 is discarded because of
lock-on-active. If you want rule2 to fire first, and not rule3, you will
have to flip their salience order. If you want both to fire, but just once,
(unless the matched properties in the LHS are changed) then use no-loop.
I'm not sure from what you've written that you want another behavior.
--- On Mon, 12/28/09, oknuutti <olli.knuuttila(a)gmail.com> wrote:
> From: oknuutti <olli.knuuttila(a)gmail.com>
> Subject: [rules-users] suprises when using auto-focus with salience or
lock-on-active
> To: rules-users(a)lists.jboss.org
> Date: Monday, December 28, 2009, 4:29 AM
>
> While evaluating Drools 5.1.0 M1, I came across two issues
> which strike me
> somewhat undesirable. Maybe there's good reasons why they
> exist; perhaps I'm
> missing something?
>
> First:
>
> If I have two agenda groups, each with a rule that has
> auto-focus set to
> true and different saliences, the group which will get the
> focus first seems
> to be determined by the order in which the auto-focused
> rules appear in the
> drl-file, not by their salience.
>
> // example snippet:
> rule "rule1"
> salience 0
> agenda-group "group1"
> auto-focus true
> when
> then
> System.out.println("rule1 fired");
> end
>
> rule "rule2"
> salience -100
> agenda-group "group2"
> auto-focus true
> when
> then
> System.out.println("rule2 fired");
> end
>
> // output of the example:
> rule2 fired
> rule1 fired
>
> If I change the salience of rule2 to 100 the result is
> still the same. It
> seems reasonable to me that the salience would be taken
> into account also in
> this situation.
>
> Second:
>
> This issue is with auto-focus and lock-on-active. If I add
> "lock-on-active
> true" to rule2 and also a third rule:
>
> // continuing the earlier example:
> rule "rule3"
> agenda-group "group2"
> when
> then
> System.out.println("rule3 fired");
> end
>
> then I get the following puzzling output:
>
> rule3 fired
> rule1 fired
>
> It seems that auto-focus activates the agenda group first
> and then tries to
> activate rule2 but the activation is discarded by
> lock-on-active. I feel
> that this is a bit too strong loop prevention. I would
> rather see rule2
> fired once, with no consecutive activations in the case
> that it would have
> some conditions that were changed by rule3.
>
> Any comments?
>
> Olli
> --
> View this message in context:
http://n3.nabble.com/suprises-when-using-auto-focus-with-salience-or-lock...
> Sent from the Drools - User mailing list archive at
>
Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users