Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-1478

Call ActivationUnMatchListener also when a rule rematches

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Obsolete
    • Major
    • 7.0.0.Beta8
    • None
    • core engine
    • None
    • NEW
    • NEW

    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

      global int score = 0;
      rule R
      when
          Wine(age < 10, $age : age)
      then
          score += $age;
          addUnmatchListener(() -> score -= $age);
      end
      

      This works for a normal match and unmatch event:

      Wine w = new Wine(3);
      insert(w);
      fireAllRules(); => score = 7;
      
      w.age = 50;
      update(w);
      fireAllRules(); => unmatch triggers => score = 0; // GOOD
      

      So events are like this:

      RHS
      unmatch
      

      However if we have a rematch:

      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.
      
      

      Because the events are unbalanced:

      RHS
      RHS
      unmatch
      

      I'd argue that anyone using the ActivationUnMatchListener would want to the have balanced events.

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: