2011/8/22 Chris Richmond <span dir="ltr">&lt;<a href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>&gt;</span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    Doesn&#39;t retracting all objects then inserting new objects cause the
    rules to be evaluated for the objects currently in working memory?<br>
    <br></div></blockquote><div><br>Mostly, yes, but rules using just not(&lt;something&gt;) may not fire again unless retracting changes it to true.<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div text="#000000" bgcolor="#FFFFFF">
    Do I need to use Stateless instead of Stateful or something?<br></div></blockquote><div><br>Both use the same reasoning.<br><br>Disposing the old session and creating a new one might be one way of achieving what you have in mind. Also, adding a pattern with a &quot;trigger&quot; fact you can change judiciously might do the trick.<br>
<br>-W<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div text="#000000" bgcolor="#FFFFFF">
    <br>
    Thanks,<br><font color="#888888">
    <br>
    Chris</font><div><div></div><div class="h5"><br>
    <br>
    On 8/19/2011 7:47 PM, Wolfgang Laun wrote:
    <blockquote type="cite">A condition based on the negated existence quantifier
      is true when no such object is in the WM. Once recognized as true,
      the rule fires, and that&#39;s it until it isn&#39;t true any more, which
      is a sort of &quot;rewind&quot; for the condition after which the begin of
      another period of absence is celebrated with another firing.
      Repeated stop-and-go of the rule engine does not influence this
      monitoring of truth.<br>
      <br>
      -W<br>
      <br>
      <br>
      <div class="gmail_quote">2011/8/20 Chris Richmond <span dir="ltr">&lt;<a href="mailto:crichmond@referentia.com" target="_blank">crichmond@referentia.com</a>&gt;</span><br>
        <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
          <div text="#000000" bgcolor="#FFFFFF"> Well..I insert some
            objects, fire the rules and this rule will trigger the first
            time (when it finds no object with those characterstis) but
            every time after than when I insert more objects and fire
            the rules, the rule never fires again. I have no idea why. 
            Here is my simple test case. <br>
            <br>
            Two clasess: TestMain and TestObject and rule file Test.drl
            I have included below.<br>
            <br>
            It insterts a group of facts at one time, fires the rules,
            and retracts all those facts from the stream.  I have an
            event listener on the session, as you see to verify
            injections and retractions are occuring.  <br>
            So the rule fires on the first batch, but on no other
            batches after that???? What gives????  <br>
            <br>
            Among the Inserttion and retraction events I only see:<br>
            <br>
            A proper object does not exist<br>
            <br>
            One time, during firing rules on the first batch.  Why does
            this rule never fire again, even though every single batch
            of objects I insert/retract does not contain the proper rule
            values, and so should fire the rule.<br>
            <br>
            What is going on???<br>
            <br>
            <br>
            <br>
            <br>
            <br>
            TestMain.java *************************************<br>
            <br>
            package com.sample;<br>
            <br>
            import java.util.ArrayList;<br>
            import java.util.List;<br>
            <br>
            import org.drools.KnowledgeBase;<br>
            import org.drools.KnowledgeBaseConfiguration;<br>
            import org.drools.KnowledgeBaseFactory;<br>
            import org.drools.builder.KnowledgeBuilder;<br>
            import org.drools.builder.KnowledgeBuilderError;<br>
            import org.drools.builder.KnowledgeBuilderErrors;<br>
            import org.drools.builder.KnowledgeBuilderFactory;<br>
            import org.drools.builder.ResourceType;<br>
            import org.drools.conf.EventProcessingOption;<br>
            import org.drools.event.rule.ObjectInsertedEvent;<br>
            import org.drools.event.rule.ObjectRetractedEvent;<br>
            import org.drools.event.rule.ObjectUpdatedEvent;<br>
            import org.drools.event.rule.WorkingMemoryEventListener;<br>
            import org.drools.io.ResourceFactory;<br>
            import org.drools.runtime.KnowledgeSessionConfiguration;<br>
            import org.drools.runtime.StatefulKnowledgeSession;<br>
            import org.drools.runtime.conf.ClockTypeOption;<br>
            import org.drools.runtime.rule.FactHandle;<br>
            import org.drools.runtime.rule.WorkingMemoryEntryPoint;<br>
            <br>
            public class TestMain {<br>
            <br>
              @SuppressWarnings(&quot;restriction&quot;)<br>
              public static void main(String[] args) {<br>
                <br>
            <br>
                try {<br>
                  <br>
                  KnowledgeSessionConfiguration config =
            KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
                  config.setOption( ClockTypeOption.get(&quot;realtime&quot;) );<br>
                  <br>
            <br>
                  KnowledgeBase kbase;<br>
                  kbase = readKnowledgeBase();<br>
                  final StatefulKnowledgeSession ksession =
            kbase.newStatefulKnowledgeSession();<br>
                  <br>
                  WorkingMemoryEntryPoint myStream =
            ksession.getWorkingMemoryEntryPoint(&quot;My Stream&quot;);<br>
                  <br>
                  ksession.addEventListener(new
            WorkingMemoryEventListener(){<br>
            <br>
                    @Override<br>
                    public void objectInserted(ObjectInsertedEvent oie)
            {<br>
                      System.err.println(&quot;Inserted: &quot; + oie.toString());<br>
                      <br>
                    }<br>
            <br>
                    @Override<br>
                    public void objectRetracted(ObjectRetractedEvent
            arg0) {<br>
                      System.err.println(&quot;Retracted: &quot; +
            arg0.toString());<br>
                      <br>
                    }<br>
            <br>
                    @Override<br>
                    public void objectUpdated(ObjectUpdatedEvent arg0) {<br>
                      // TODO Auto-generated method stub<br>
                      <br>
                    }<br>
                    <br>
                  });<br>
                  <br>
            <br>
                  for (int a = 0; a &lt; 1000; a++){<br>
                    List&lt;FactHandle&gt; factHandles = new
            ArrayList&lt;FactHandle&gt;();<br>
                    for (int x = 0; x &lt; 6; x++){<br>
                      <br>
                      double reading = 11.3;<br>
                      float f = (float)reading;<br>
                      TestObject dr = new TestObject(&quot;Reading &quot; + x, f);<br>
                      FactHandle fh = myStream.insert(dr);<br>
                      factHandles.add(fh);<br>
            <br>
                <br>
                      <br>
                    }<br>
                    ksession.fireAllRules();<br>
                    for(FactHandle fh : factHandles){<br>
                      myStream.retract(fh);<br>
                    }<br>
                    Thread.sleep(4000);<br>
                  }<br>
                  <br>
                } catch (Exception e) {<br>
                  // TODO Auto-generated catch block<br>
                  e.printStackTrace();<br>
                }<br>
            <br>
              }<br>
            <br>
              @SuppressWarnings(&quot;restriction&quot;)<br>
              private static KnowledgeBase readKnowledgeBase() throws
            Exception {<br>
                KnowledgeBuilder kbuilder =
            KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
               
            kbuilder.add(ResourceFactory.newClassPathResource(&quot;Test.drl&quot;),
            ResourceType.DRL);<br>
                KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
                if (errors.size() &gt; 0) {<br>
                  for (KnowledgeBuilderError error: errors) {<br>
                    System.err.println(error);<br>
                  }<br>
                  throw new IllegalArgumentException(&quot;Could not parse
            knowledge.&quot;);<br>
                }<br>
                <br>
                KnowledgeBaseConfiguration kbConfig =
            KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
                kbConfig.setOption( EventProcessingOption.STREAM );<br>
                KnowledgeBase kbase =
            KnowledgeBaseFactory.newKnowledgeBase(kbConfig);<br>
               
            kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
                <br>
                <br>
            <br>
            <br>
                return kbase;<br>
              }<br>
            <br>
              <br>
            <br>
            <br>
            }<br>
            <br>
            TestObject.java *************************************<br>
            package com.sample;<br>
            <br>
            public class TestObject {<br>
            <br>
              <br>
            <br>
              private String name;<br>
              private float reading;<br>
              <br>
              <br>
              public TestObject(String name, float reading){<br>
                <a href="http://this.name" target="_blank">this.name</a> = name;<br>
                this.reading = reading;<br>
              }<br>
            <br>
            <br>
              public String getName() {<br>
                return name;<br>
              }<br>
            <br>
            <br>
              public void setName(String name) {<br>
                <a href="http://this.name" target="_blank">this.name</a> = name;<br>
              }<br>
            <br>
            <br>
              public float getReading() {<br>
                return reading;<br>
              }<br>
            <br>
            <br>
              public void setReading(float reading) {<br>
                this.reading = reading;<br>
              }<br>
            }<br>
            <br>
            <br>
            Test.drl*************************************************<br>
            #created on: Aug 19, 2011<br>
            package com.sample<br>
            <br>
            <br>
            <br>
            rule &quot;Test For Lack of Objects with criteria&quot;<br>
                <br>
            when<br>
                    not(TestObject(name==&quot;blah&quot;)  from entry-point &quot;My
            Stream&quot;)<br>
            then<br>
                    System.err.println(&quot;A proper object does not
            exist&quot;);<br>
            end<br>
            <br>
            <br>
            <br>
            <br>
            On 8/18/2011 8:46 PM, Wolfgang Laun wrote:
            <blockquote type="cite">On 19 August 2011 15:17, Chris
              Richmond <span dir="ltr">&lt;<a href="mailto:crichmond@referentia.com" target="_blank">crichmond@referentia.com</a>&gt;</span>
              wrote:<br>
              <div class="gmail_quote">
                <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> How do I fire a rule if an object
                  with certain characterstics does not<br>
                  exists.<br>
                  <br>
                  For example my class Foo, if I have a rule:<br>
                  <br>
                  rule &quot;Identify Foos with values&quot;<br>
                  <br>
                  when<br>
                          Foo(stringProp==&quot;blah&quot;, intProp==5)<br>
                  then<br>
                          System.err.println(&quot;A Foo was found!&quot;);<br>
                  end<br>
                  <br>
                  <br>
                  So how do I check for lack of existence of an object
                  with certain<br>
                  characteristics<br>
                  <br>
                  I tried:<br>
                  rule &quot;Flag missing Foos with values&quot;<br>
                  <br>
                  when<br>
                          not(Foo(stringProp==&quot;blah&quot;, intProp==5))<br>
                  then<br>
                          System.err.println(&quot;A proper foo does not
                  exist&quot;);<br>
                  end<br>
                </blockquote>
                <div><br>
                  That&#39;s the way to do it.<br>
                   </div>
                <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> <br>
                  I also tried:<br>
                  rule &quot;Flag missing Foos with values&quot;<br>
                  <br>
                  when<br>
                          not(exists(Foo(stringProp==&quot;blah&quot;,
                  intProp==5)))<br>
                  then<br>
                          System.err.println(&quot;A proper foo does not
                  exist&quot;);<br>
                  end<br>
                </blockquote>
                <div><br>
                  Since not( Foo(...)) means &quot;if no Foo(...) exists&quot;,
                  the addition of &quot;exists&quot; is superfluous and generally
                  considered bad style (even though some systems accept
                  it to mean just &quot;not&quot;.<br>
                  <br>
                  -W<br>
                   </div>
                <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
                  _______________________________________________<br>
                  rules-users mailing list<br>
                  <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
                  <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
                </blockquote>
              </div>
              <br>
              <br>
              <fieldset></fieldset>
              <br>
              <pre>_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
            </blockquote>
            <br>
          </div>
          <br>
          _______________________________________________<br>
          rules-users mailing list<br>
          <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
          <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
          <br>
        </blockquote>
      </div>
      <br>
      <br>
      <fieldset></fieldset>
      <br>
      <pre>_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
    </blockquote>
    <br>
  </div></div></div>

<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>