Drools retraction is causing rule not to fire
I'm coming across some weird behavior in Drools 4.0.7, but maybe it's just cause I don't understand I how Drools works. Assume, there's a class "A" that has a property called "property".
As facts, I have the follo开发者_如何学Cwing list of A's: A1, property = 123 A2, property = 345 A3, property = 123
I have two rules as follows:
rule "Rule 1 - Remove all A's that have property set to 123"
salience 1000
lock-on-active true
when
$listOfAs : ArrayList collect(A( property == "123" ))
then
for (Object a: $listOfAs ) {
retract (a)
}
end
rule "Rule 2 - Do stuff with remaining A's"
salience 900
lock-on-active true
when
$listOfAs : ArrayList collect(A())
then
...
end
My understanding is "Rule 1" will remove the facts of class A that have property to 123. When it gets to "Rule 2", shouldn't the "listOfAs" only have that one A that remains (i.e. the one where property is set to "345"). What I'm noticing is that "Rule 2" just doesn't execute at all even though I'm assuming there is still one "A" object that hasn't been retracted. If I comment out the "retract" it executes "Rule 2" fine.
Am I missing something about these rules work?
Thanks. Justin
I suspect that the problem here is the use of 'lock-on-active'. Given that the first rule has activated, it prevents the other rule from also activating.
According to the docs lock-on-active is:
"A Boolean value. "true" inhibits additional activations of all rules with this flag set within the same ruleflow or agenda group."
精彩评论