The insertion of DataReading events happens &quot;instantaneously&quot;, without Drools regaining &quot;consciousness&quot; 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&#39;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 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>
   public static final void main(String[] args) {<br>
<br>
<br>
<br>
<br>
     try {<br>
<br>
       KnowledgeSessionConfiguration config =<br>
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();<br>
       config.setOption( ClockTypeOption.get(&quot;realtime&quot;) );<br>
       KnowledgeBase kbase;<br>
       kbase = readKnowledgeBase();<br>
       final StatefulKnowledgeSession ksession =<br>
kbase.newStatefulKnowledgeSession();<br>
<br>
       WorkingMemoryEntryPoint myStream =<br>
ksession.getWorkingMemoryEntryPoint(&quot;My Stream&quot;);<br>
<br>
       Thread t = new Thread(new Runnable(){<br>
<br>
         @Override<br>
         public void run() {<br>
           ksession.fireUntilHalt();<br>
<br>
         }<br>
<br>
       });<br>
<br>
       t.start();<br>
<br>
       for (float x = 0.0f; x &lt; 20.0f; x++){<br>
         DataReading dr = new DataReading(&quot;Reading &quot; + x, x);<br>
         myStream.insert(dr);<br>
       }<br>
<br>
<br>
     } catch (Exception e) {<br>
       // TODO Auto-generated catch block<br>
       e.printStackTrace();<br>
     }<br>
<br>
   }<br>
<br>
   private static KnowledgeBase readKnowledgeBase() throws Exception {<br>
     KnowledgeBuilder kbuilder =<br>
KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
     kbuilder.add(ResourceFactory.newClassPathResource(&quot;Sample.drl&quot;),<br>
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>
     KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();<br>
     kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
     return kbase;<br>
   }<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>
     @role( event )<br>
<br>
end<br>
<br>
rule &quot;MyGuidedRule&quot;<br>
     dialect &quot;mvel&quot;<br>
     when<br>
         $dr: DataReading( reading &gt; &quot;10.0&quot; ) from entry-point &quot;My Stream&quot;<br>
     then<br>
         System.err.println(&quot;Reading: &quot; +  $<a href="http://dr.name" target="_blank">dr.name</a> + &quot; &gt; 10.0 &quot; +<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 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>
</blockquote></div><br>