would_like_to_be_anon
would_like_to_be_anon

Reputation: 1727

drools agenda-group lock-on-active doesn't seem to be working for me

In the below rules, I want the rule1 to be executed first for each clazz1, and only if it is satisfied, the other rules need to be executed ( because of lock-on-active )

However, after rule1 is executed, drools is executing rule1, rule2, rule3 and rule2, rule3, and then back to rule1.

Could you suggest if my configuration is incorrect?

rule "rule1"
ruleflow-group "validate_precondition"
    when
        $clazz1 : Clazz1 ( isPreConditionSatisfied() )
    then
        drools.setFocus("validate1");
end

rule "rule2"
agenda-group "validate1"
lock-on-active true
    when
        $clazz1 : Clazz1 ( !isCheck1(type) )
    then
        System.out.println("inside check1");
end

rule "rule3"
agenda-group "validate1"
lock-on-active true
    when
        $clazz1 : Clazz1 ( !isCheck2(type) )
    then
        System.out.println("inside check2");
end

Upvotes: 0

Views: 2062

Answers (1)

Steve
Steve

Reputation: 9480

From the Drools manual:

Whenever a ruleflow-group becomes active or an agenda-group receives the focus, any rule within that group that has lock-on-active set to true will not be activated any more ... when the agenda-group loses the focus those rules with lock-on-active set to true become eligible again for their activations to be placed onto the agenda.

So given that each of your rules is in a different agenda-group, and you're changing focus after each rule activation, using lock-on-active won't achieve anything.

From what you are saying, it sounds like the rules engine is activating multiple times. Assuming that it's not cycling in an infinite loop, I would expect this to be due to more than one instance of Clazz1 in working memory.

If it is cycling in an infinite loop, then I would hazard a guess that the code above is not what you're executing. An infinite loop in these situations tends to be caused by rules which update a fact, without using "no-loop".

One additional note - you should seriously reconsider whether it is appropriate to be enforcing an order to the execution of these rules. At least with the examples above there seems to be no good reason for doing this.

Upvotes: 1

Related Questions