]
Mario Fusco resolved DROOLS-1478.
---------------------------------
Fix Version/s: 7.0.0.Beta8
Resolution: Out of Date
Replaced by
Call ActivationUnMatchListener also when a rule rematches
---------------------------------------------------------
Key: DROOLS-1478
URL:
https://issues.jboss.org/browse/DROOLS-1478
Project: Drools
Issue Type: Enhancement
Components: core engine
Reporter: Geoffrey De Smet
Assignee: Mario Fusco
Fix For: 7.0.0.Beta8
ActivationUnMatchListener is part of kie-internal, so its *not public API*.
*ActivationUnMatchListener is only used by OptaPlanner* (probably):
jBPM and downstream drools module don't use it:
https://github.com/search?q=org%3Akiegroup+ActivationUnMatchListener&...
Community users probably don't use it either, because no one mentions it on
StackOverflow:
https://www.google.be/search?q=%2BActivationUnMatchListener+site:stackove...
----
The current behaviour of ActivationUnMatchListener is a pain because it doesn't
unmatch if a RHS fires again, causing an imbalance. OptaPlanner works around this through
a hack (which fails for PLANNER-761).
For example, given this rule
{code}
global int score = 0;
rule R
when
Wine(age < 10, $age : age)
then
score += $age;
addUnmatchListener(() -> score -= $age);
end
{code}
This works for a normal match and unmatch event:
{code}
Wine w = new Wine(3);
insert(w);
fireAllRules(); => score = 7;
w.age = 50;
update(w);
fireAllRules(); => unmatch triggers => score = 0; // GOOD
{code}
So events are like this:
{code}
RHS
unmatch
{code}
However if we have a rematch:
{code}
Wine w = new Wine(3);
insert(w);
fireAllRules(); => score = 7;
w.age = 4;
update(w);
fireAllRules(); => no unmatch triggers => score = 13; // BAD Should be 6. Unmatch
should have triggered.
w.age = 50;
update(w);
fireAllRules(); => unmatch triggers => score = 7; // Should be 0.
{code}
Because the events are unbalanced:
{code}
RHS
RHS
unmatch
{code}
I'd argue that anyone using the ActivationUnMatchListener would want to the have
balanced events.