Thanks for your clarifications and thoughts.
My misunderstanding was because I always thought that lock-on-active meant
lock-on-RULE-active. Something like lock after the first activation and do
not unlock until the agenda group is changed.
The real meaning is lock-on-AGENDA_GROUP-active. Meaning: do not create
activations of this rule (no matter if using update(), modify(), insert()
or retract()) if the agenda group where it belongs is active.
Best Regards!
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti
- Blog @
On Thu, Nov 15, 2012 at 7:54 AM, Mattias Nilsson Grip <
mattias.nilsson.grip(a)redpill-linpro.com> wrote:
Armand/Esteban,
I had a look at source code (
org.drools.common.DefaultAgenda.createActivation(...) ) and as far as I can
tell it should not matter if the rules match on the same facts or not. I
interpret the source code like this:
"While an agenda group or rule flow group is active, any rules within that
group with lock-on-active set to true are prevented from creating new
activations"
I.e. the rule "Rule 1" cannot create an activation since its agenda group
MAIN is already active when its conditions are fulfilled.
Regards,
Mattias
----- Original Message -----
From: "Armand Welsh" <AWelsh(a)statestreet.com>
To: "Rules Users List" <rules-users(a)lists.jboss.org>
Sent: Wednesday, 14 November, 2012 11:04:36 PM
Subject: Re: [rules-users] lock-on-active clarification needed
Esteban,
I too have been confused by lock-on-active. Only after reading the
definition many times, have I come to the following conclusion:
Looking at the documentation, and other examples, I think I can how
lock-on-active behaves. From what I gather, it looks like when “init “ rule
fires, the activations for that rule consist of the DataSample() facts (all
of them). You then modify the fact, but at the same time, the
lock-on-active blocks any further activations from occur as a result of
modifying the DataSample() fact.
Since “Rule 1” depends on DataSample, and it is in the same agenda group
as init, “Rule 1” cannot fire until the agenda group is changed, or the
ruleflow-group is changed.
What is being blocked by lock-on-active is not the reactivation of the
rule. What is being blocked is the resultant activations as a result of
modify the DataSample fact.
This block only holds true on the current focus (agenda-group or
ruleflow-group). Think of it as a way of temporarily removing the facts
from the knowledge tree.
From: rules-users-bounces(a)lists.jboss.org [mailto:
rules-users-bounces(a)lists.jboss.org] On Behalf Of Esteban Aliverti
Sent: Wednesday, November 14, 2012 3:41 AM
To: Rules Users List
Subject: [rules-users] lock-on-active clarification needed
Hi all,
I'm dealing with a set of rules having the lock-on-active attribute and
I'm not getting the (at least what I understand as) expected results.
I've created an isolated JUnit test. I'm attaching it to this email.
Basically, I have 2 rules:
rule "init"
lock-on-active true
when
$d: DataSample()
then
System.out.println("Setting predefined value");
modify($d){
addValue(Parameter.PARAM_A, 10.0)
}
end
rule "Rule 1"
lock-on-active true
when
DataSample($v: values[Parameter.PARAM_A] < 20)
then
System.out.println("Rule 1: "+$v);
end
DataSample is a Java class containing a Map<Parameter, Double> where
Parameter is an enum.
In the test I'm creating a ksession and inserting an empty DataSample
object.
I understand that as soon as the object is inserted, both rules are
evaluated and the result is going to be an activation of rule "init"; and
this is what is actually happening. So far so good.
Now, after I call fireAllRules() I expect that 'Rule 1' becomes active
because of the modification of the fact in "init". Well, this is not the
case. I don't see any activation for "Rule 1".
My understanding about lock-on-active is that a rule that WAS ACTIVATED is
not going to be re-activated until the current agenda group is switched.
The odd thing here is that I never had an activation for "Rule 1" so I
don't see why it activation after "init" is executed should be prevented.
So my question is: Is my understanding wrong? What is the expected
behavior of lock-on-active in this situation? I read the documentation but
I couldn't get any hint:
"
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 ; irrespective of the origin of the update, the
activation of a matching rule is discarded. This is a stronger version of
no-loop, because the change could now be caused not only by the rule
itself. It's ideal for calculation rules where you have a number of rules
that modify a fact and you don't want any rule re-matching and firing
again. Only when the ruleflow-group is no longer active or 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."
Best Regards,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti
- Blog @
http://ilesteban.wordpress.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