<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body 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.&nbsp;
    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.&nbsp; I have an event listener
    on the session, as you see to verify injections and retractions are
    occuring.&nbsp; <br>
    So the rule fires on the first batch, but on no other batches after
    that???? What gives????&nbsp; <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.&nbsp; 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>
    &nbsp; @SuppressWarnings("restriction")<br>
    &nbsp; public static void main(String[] args) {<br>
    &nbsp;&nbsp;&nbsp; <br>
    <br>
    &nbsp;&nbsp;&nbsp; try {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KnowledgeSessionConfiguration config =
    KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.setOption( ClockTypeOption.get("realtime") );<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; KnowledgeBase kbase;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kbase = readKnowledgeBase();<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final StatefulKnowledgeSession ksession =
    kbase.newStatefulKnowledgeSession();<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WorkingMemoryEntryPoint myStream =
    ksession.getWorkingMemoryEntryPoint("My Stream");<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ksession.addEventListener(new WorkingMemoryEventListener(){<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Override<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void objectInserted(ObjectInsertedEvent oie) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.err.println("Inserted: " + oie.toString());<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Override<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void objectRetracted(ObjectRetractedEvent arg0) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.err.println("Retracted: " + arg0.toString());<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @Override<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void objectUpdated(ObjectUpdatedEvent arg0) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // TODO Auto-generated method stub<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int a = 0; a &lt; 1000; a++){<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;FactHandle&gt; factHandles = new
    ArrayList&lt;FactHandle&gt;();<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int x = 0; x &lt; 6; x++){<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double reading = 11.3;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; float f = (float)reading;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TestObject dr = new TestObject("Reading " + x, f);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FactHandle fh = myStream.insert(dr);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; factHandles.add(fh);<br>
    <br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ksession.fireAllRules();<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(FactHandle fh : factHandles){<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myStream.retract(fh);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Thread.sleep(4000);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; } catch (Exception e) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // TODO Auto-generated catch block<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();<br>
    &nbsp;&nbsp;&nbsp; }<br>
    <br>
    &nbsp; }<br>
    <br>
    &nbsp; @SuppressWarnings("restriction")<br>
    &nbsp; private static KnowledgeBase readKnowledgeBase() throws Exception
    {<br>
    &nbsp;&nbsp;&nbsp; KnowledgeBuilder kbuilder =
    KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
    &nbsp;&nbsp;&nbsp; kbuilder.add(ResourceFactory.newClassPathResource("Test.drl"),
    ResourceType.DRL);<br>
    &nbsp;&nbsp;&nbsp; KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
    &nbsp;&nbsp;&nbsp; if (errors.size() &gt; 0) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (KnowledgeBuilderError error: errors) {<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.err.println(error);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new IllegalArgumentException("Could not parse
    knowledge.");<br>
    &nbsp;&nbsp;&nbsp; }<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; KnowledgeBaseConfiguration kbConfig =
    KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
    &nbsp;&nbsp;&nbsp; kbConfig.setOption( EventProcessingOption.STREAM );<br>
    &nbsp;&nbsp;&nbsp; KnowledgeBase kbase =
    KnowledgeBaseFactory.newKnowledgeBase(kbConfig);<br>
    &nbsp;&nbsp;&nbsp; kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
    &nbsp;&nbsp;&nbsp; <br>
    &nbsp;&nbsp;&nbsp; <br>
    <br>
    <br>
    &nbsp;&nbsp;&nbsp; return kbase;<br>
    &nbsp; }<br>
    <br>
    &nbsp; <br>
    <br>
    <br>
    }<br>
    <br>
    TestObject.java *************************************<br>
    package com.sample;<br>
    <br>
    public class TestObject {<br>
    <br>
    &nbsp; <br>
    <br>
    &nbsp; private String name;<br>
    &nbsp; private float reading;<br>
    &nbsp; <br>
    &nbsp; <br>
    &nbsp; public TestObject(String name, float reading){<br>
    &nbsp;&nbsp;&nbsp; this.name = name;<br>
    &nbsp;&nbsp;&nbsp; this.reading = reading;<br>
    &nbsp; }<br>
    <br>
    <br>
    &nbsp; public String getName() {<br>
    &nbsp;&nbsp;&nbsp; return name;<br>
    &nbsp; }<br>
    <br>
    <br>
    &nbsp; public void setName(String name) {<br>
    &nbsp;&nbsp;&nbsp; this.name = name;<br>
    &nbsp; }<br>
    <br>
    <br>
    &nbsp; public float getReading() {<br>
    &nbsp;&nbsp;&nbsp; return reading;<br>
    &nbsp; }<br>
    <br>
    <br>
    &nbsp; public void setReading(float reading) {<br>
    &nbsp;&nbsp;&nbsp; this.reading = reading;<br>
    &nbsp; }<br>
    }<br>
    <br>
    <br>
    Test.drl*************************************************<br>
    #created on: Aug 19, 2011<br>
    package com.sample<br>
    <br>
    <br>
    <br>
    rule "Test For Lack of Objects with criteria"<br>
    &nbsp;&nbsp;&nbsp; <br>
    when<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; not(TestObject(name=="blah")&nbsp; from entry-point "My Stream")<br>
    then<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.err.println("A proper object does not exist");<br>
    end<br>
    <br>
    <br>
    <br>
    <br>
    On 8/18/2011 8:46 PM, Wolfgang Laun wrote:
    <blockquote
cite="mid:CANaj1LfSg77owDTipmep1zXjQsq-K+K2xiYZSWPqE4R1u7__6g@mail.gmail.com"
      type="cite">On 19 August 2011 15:17, Chris Richmond <span
        dir="ltr">&lt;<a moz-do-not-send="true"
          href="mailto:crichmond@referentia.com">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 "Identify Foos with values"<br>
          <br>
          when<br>
          &nbsp; &nbsp; &nbsp; &nbsp; Foo(stringProp=="blah", intProp==5)<br>
          then<br>
          &nbsp; &nbsp; &nbsp; &nbsp; System.err.println("A Foo was found!");<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 "Flag missing Foos with values"<br>
          <br>
          when<br>
          &nbsp; &nbsp; &nbsp; &nbsp; not(Foo(stringProp=="blah", intProp==5))<br>
          then<br>
          &nbsp; &nbsp; &nbsp; &nbsp; System.err.println("A proper foo does not exist");<br>
          end<br>
        </blockquote>
        <div><br>
          That's the way to do it.<br>
          &nbsp;</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 "Flag missing Foos with values"<br>
          <br>
          when<br>
          &nbsp; &nbsp; &nbsp; &nbsp; not(exists(Foo(stringProp=="blah", intProp==5)))<br>
          then<br>
          &nbsp; &nbsp; &nbsp; &nbsp; System.err.println("A proper foo does not exist");<br>
          end<br>
        </blockquote>
        <div><br>
          Since not( Foo(...)) means "if no Foo(...) exists", the
          addition of "exists" is superfluous and generally considered
          bad style (even though some systems accept it to mean just
          "not".<br>
          <br>
          -W<br>
          &nbsp;</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 moz-do-not-send="true"
            href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
          <a moz-do-not-send="true"
            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 class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>