Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-614

logically asserted facts do not get retracted properly

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 4.0.0.MR2
    • 3.0.5
    • None
    • None
    • Documentation (Ref Guide, User Guide, etc.)
    • Workaround Exists
    • Hide

      Instead of modifying a fact via setter someone can use a "retract/(re-)assert" approach to relaize modification. This leads to correcpt retraction of logically asserted facts - moreover it ensures that there exists only one instance of a specific logically asserted fact in the working memory at any time.

      Show
      Instead of modifying a fact via setter someone can use a "retract/(re-)assert" approach to relaize modification. This leads to correcpt retraction of logically asserted facts - moreover it ensures that there exists only one instance of a specific logically asserted fact in the working memory at any time.

    Description

      1) Setup the following rules:

      rule "#1: value out of range (verification)"
      when
      val : Value( value > 100 )
      then
      System.out.println("found invalid value: " + val.getValue());

      assertLogical(new Message("value out of range"));
      end

      rule "#2: value out of range (print out)"
      when
      Message( message == "value out of range" )
      then
      System.out.println("value out of range");
      end

      2) Assert a Value fact that triggers rule #1 (note that the Value Bean provides Property Change Support for its "value" attribute):

      // assert fact - invalid value
      Value value = new Value(101);
      FactHandle handle = workingMemory.assertObject(value);

      workingMemory.fireAllRules();

      => Output looks like this:

      found invalid value: 101
      value out of range
      — working memory dump —
      class com.sample.Value: value = 101
      class com.sample.Message: value out of range

      3) Now modify the Value fact:

      // modify fact - invalid value
      value.setValue(102);
      workingMemory.modifyObject(handle, value);

      workingMemory.fireAllRules();

      => Output looks like this:

      found invalid value: 102
      value out of range
      — working memory dump —
      class com.sample.Value: value = 102
      class com.sample.Message: value out of range
      class com.sample.Message: value out of range

      => A bit strange here: we have two Message objects - but this could be ok if both objects get retracted after modifying Value fact's value, so that it does not support the truth for rule #1... let's test

      4) Modify the value fact again:

      // modify fact - valid value
      value.setValue(100);
      workingMemory.modifyObject(handle, value);

      workingMemory.fireAllRules();

      => Output looks like this:

      <none>
      — working memory dump —
      class com.sample.Value: value = 100
      class com.sample.Message: value out of range

      Conclusion: There is still a Message fact in the working memory that was asserted logically (by rule) due to the fact Value ( value > 100 ), which does not exist any more! The (second) Message fact must be retracted too OR logically asserted facts must be asserted only once (even if the according rule is triggered multiple times). Otherwise the statement in the documentation is incorrect (chapter 3.5.2): "assertLogical(new Something());" is similar to assert, but the object will be automatically retracted when there are no more facts to support the truth of the currently firing rule".

      Attachments

        Activity

          People

            etirelli@redhat.com Edson Tirelli
            prechberger_jira Philipp Rechberger (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Resolved:
              Archived:

              PagerDuty