[jboss-jira] [JBoss JIRA] (DROOLS-1478) Call ActivationUnMatchListener also when a rule rematches
Geoffrey De Smet (JIRA)
issues at jboss.org
Wed Mar 15 11:12:00 EDT 2017
[ https://issues.jboss.org/browse/DROOLS-1478?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Geoffrey De Smet updated DROOLS-1478:
-------------------------------------
Description:
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&type=Code
Community users probably don't use it either, because no one mentions it on StackOverflow:
https://www.google.be/search?q=%2BActivationUnMatchListener+site:stackoverflow.com&*
----
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}
was:
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&type=Code
Community users probably don't use it either, because no one mentions it on StackOverflow:
https://www.google.be/search?q=%2BActivationUnMatchListener+site:stackoverflow.com&*
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}
> 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
>
> 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&type=Code
> Community users probably don't use it either, because no one mentions it on StackOverflow:
> https://www.google.be/search?q=%2BActivationUnMatchListener+site:stackoverflow.com&*
> ----
> 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}
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)
More information about the jboss-jira
mailing list