<!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"><<a moz-do-not-send="true"
href="mailto:crichmond@referentia.com">crichmond@referentia.com</a>></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("realtime") );<br>
KnowledgeBase kbase;<br>
kbase = readKnowledgeBase();<br>
final StatefulKnowledgeSession ksession =<br>
kbase.newStatefulKnowledgeSession();<br>
<br>
WorkingMemoryEntryPoint myStream =<br>
ksession.getWorkingMemoryEntryPoint("My Stream");<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 < 20.0f; x++){<br>
DataReading dr = new DataReading("Reading " + 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("Sample.drl"),<br>
ResourceType.DRL);<br>
KnowledgeBuilderErrors errors = kbuilder.getErrors();<br>
if (errors.size() > 0) {<br>
for (KnowledgeBuilderError error: errors) {<br>
System.err.println(error);<br>
}<br>
throw new IllegalArgumentException("Could not parse
knowledge.");<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 "MyGuidedRule"<br>
dialect "mvel"<br>
when<br>
$dr: DataReading( reading > "10.0" ) from
entry-point "My Stream"<br>
then<br>
System.err.println("Reading: " + $<a
moz-do-not-send="true" href="http://dr.name" target="_blank">dr.name</a>
+ " > 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 > 10.0 1311325346490<br>
Reading: Reading 18.0 > 10.0 1311325346491<br>
Reading: Reading 17.0 > 10.0 1311325346491<br>
Reading: Reading 16.0 > 10.0 1311325346491<br>
Reading: Reading 15.0 > 10.0 1311325346491<br>
Reading: Reading 14.0 > 10.0 1311325346491<br>
Reading: Reading 13.0 > 10.0 1311325346491<br>
Reading: Reading 12.0 > 10.0 1311325346491<br>
Reading: Reading 11.0 > 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>