<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Wolfgang,<br>
    <br>
    Thanks very much for that explanation, it cleared up many questions.<br>
    <br>
    "...If the order of your concurrently arriving events is essential,
    you may have to insert an ordinal as a property..."<br>
    <br>
    Can you expand on this idea or in an general practice for handling
    real time streams of data that need to be processed in order they
    were injected?<br>
    <br>
    Thanks,<br>
    Chris<br>
    <br>
    <br>
    <br>
    <br>
    On 7/21/2011 7:54 PM, Wolfgang Laun wrote:
    <blockquote
cite="mid:CANaj1Ld0ux72oL8KcRQq6+zc=Q-dumBrp1vXrYZJicxaj_+gbg@mail.gmail.com"
      type="cite">The insertion of DataReading events happens
      "instantaneously", without Drools regaining "consciousness" in
      between. So, when the Engine wakes up, it finds 20 activations in
      its agenda, with the same salience. Tie breaking is defined to use
      LIFO.<br>
      <br>
      Running the Engine in real time, these 20 events are indeed
      concurrently from the Engine's point of view, and any order of
      firings is justified; all the more so because your rule contains
      nothing to prefer a firing of an older event.<br>
      <br>
      If the order of your concurrently arriving events is essential,
      you may have to insert an ordinal as a property.<br>
      <br>
      Cheers<br>
      -W<br>
      <br>
      <div class="gmail_quote">On 22 July 2011 11:07, 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>
        <blockquote class="gmail_quote" style="border-left: 1px solid
          rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
          1ex;">I am running a simple test like so:<br>
          <br>
          package com.sample;<br>
          <br>
          import org.drools.KnowledgeBase;<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.io.ResourceFactory;<br>
          import org.drools.logger.KnowledgeRuntimeLogger;<br>
          import org.drools.logger.KnowledgeRuntimeLoggerFactory;<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.WorkingMemoryEntryPoint;<br>
          <br>
          import com.sample.DroolsTest.Message;<br>
          <br>
          public class FusionMain {<br>
          <br>
          &nbsp; public static final void main(String[] args) {<br>
          <br>
          <br>
          <br>
          <br>
          &nbsp; &nbsp; try {<br>
          <br>
          &nbsp; &nbsp; &nbsp; KnowledgeSessionConfiguration config =<br>
          KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
          &nbsp; &nbsp; &nbsp; config.setOption( ClockTypeOption.get("realtime") );<br>
          &nbsp; &nbsp; &nbsp; KnowledgeBase kbase;<br>
          &nbsp; &nbsp; &nbsp; kbase = readKnowledgeBase();<br>
          &nbsp; &nbsp; &nbsp; final StatefulKnowledgeSession ksession =<br>
          kbase.newStatefulKnowledgeSession();<br>
          <br>
          &nbsp; &nbsp; &nbsp; WorkingMemoryEntryPoint myStream =<br>
          ksession.getWorkingMemoryEntryPoint("My Stream");<br>
          <br>
          &nbsp; &nbsp; &nbsp; Thread t = new Thread(new Runnable(){<br>
          <br>
          &nbsp; &nbsp; &nbsp; &nbsp; @Override<br>
          &nbsp; &nbsp; &nbsp; &nbsp; public void run() {<br>
          &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ksession.fireUntilHalt();<br>
          <br>
          &nbsp; &nbsp; &nbsp; &nbsp; }<br>
          <br>
          &nbsp; &nbsp; &nbsp; });<br>
          <br>
          &nbsp; &nbsp; &nbsp; t.start();<br>
          <br>
          &nbsp; &nbsp; &nbsp; for (float x = 0.0f; x &lt; 20.0f; x++){<br>
          &nbsp; &nbsp; &nbsp; &nbsp; DataReading dr = new DataReading("Reading " + x, x);<br>
          &nbsp; &nbsp; &nbsp; &nbsp; myStream.insert(dr);<br>
          &nbsp; &nbsp; &nbsp; }<br>
          <br>
          <br>
          &nbsp; &nbsp; } catch (Exception e) {<br>
          &nbsp; &nbsp; &nbsp; // TODO Auto-generated catch block<br>
          &nbsp; &nbsp; &nbsp; e.printStackTrace();<br>
          &nbsp; &nbsp; }<br>
          <br>
          &nbsp; }<br>
          <br>
          &nbsp; private static KnowledgeBase readKnowledgeBase() throws
          Exception {<br>
          &nbsp; &nbsp; KnowledgeBuilder kbuilder =<br>
          KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
          &nbsp; &nbsp;
          kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),<br>
          ResourceType.DRL);<br>
          &nbsp; &nbsp; KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
          &nbsp; &nbsp; if (errors.size() &gt; 0) {<br>
          &nbsp; &nbsp; &nbsp; for (KnowledgeBuilderError error: errors) {<br>
          &nbsp; &nbsp; &nbsp; &nbsp; System.err.println(error);<br>
          &nbsp; &nbsp; &nbsp; }<br>
          &nbsp; &nbsp; &nbsp; throw new IllegalArgumentException("Could not parse
          knowledge.");<br>
          &nbsp; &nbsp; }<br>
          &nbsp; &nbsp; KnowledgeBase kbase =
          KnowledgeBaseFactory.newKnowledgeBase();<br>
          &nbsp; &nbsp;
          kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
          &nbsp; &nbsp; return kbase;<br>
          &nbsp; }<br>
          <br>
          <br>
          }<br>
          <br>
          With the following rule in the sample.drl file:<br>
          <br>
          package com.sample<br>
          import com.sample.DroolsTest.Message;<br>
          import java.util.Date;<br>
          <br>
          declare DataReading<br>
          &nbsp; &nbsp; @role( event )<br>
          <br>
          end<br>
          <br>
          rule "MyGuidedRule"<br>
          &nbsp; &nbsp; dialect "mvel"<br>
          &nbsp; &nbsp; when<br>
          &nbsp; &nbsp; &nbsp; &nbsp; $dr: DataReading( reading &gt; "10.0" ) from
          entry-point "My Stream"<br>
          &nbsp; &nbsp; then<br>
          &nbsp; &nbsp; &nbsp; &nbsp; System.err.println("Reading: " + &nbsp;$<a
            moz-do-not-send="true" href="http://dr.name" target="_blank">dr.name</a>
          + " &gt; 10.0 " +<br>
          System.currentTimeMillis());<br>
          end<br>
          <br>
          know I am running fireUntilHalt on a seperate thread as you
          can see, but<br>
          events injected fire rules out of order...in fact almost the
          exact<br>
          opposite order in which they were inserted to the stream every
          time:<br>
          <br>
          Reading: Reading 19.0 &gt; 10.0 1311325346490<br>
          Reading: Reading 18.0 &gt; 10.0 1311325346491<br>
          Reading: Reading 17.0 &gt; 10.0 1311325346491<br>
          Reading: Reading 16.0 &gt; 10.0 1311325346491<br>
          Reading: Reading 15.0 &gt; 10.0 1311325346491<br>
          Reading: Reading 14.0 &gt; 10.0 1311325346491<br>
          Reading: Reading 13.0 &gt; 10.0 1311325346491<br>
          Reading: Reading 12.0 &gt; 10.0 1311325346491<br>
          Reading: Reading 11.0 &gt; 10.0 1311325346491<br>
          <br>
          I want to eventually perform temporal reasoning, but how can I
          expect<br>
          that to work if events are not evaluated in the order they
          were inserted.<br>
          <br>
          Perhaps I am setting up my session/kb improperly?<br>
          <br>
          Thanks,<br>
          Chris<br>
          _______________________________________________<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>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
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>