On 22 July 2011 11:07, Chris Richmond
<crichmond@referentia.com>
wrote:
I am running a simple test like so:
package com.sample;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.conf.ClockTypeOption;
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
import com.sample.DroolsTest.Message;
public class FusionMain {
public static final void main(String[] args) {
try {
KnowledgeSessionConfiguration config =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
config.setOption( ClockTypeOption.get("realtime") );
KnowledgeBase kbase;
kbase = readKnowledgeBase();
final StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
WorkingMemoryEntryPoint myStream =
ksession.getWorkingMemoryEntryPoint("My Stream");
Thread t = new Thread(new Runnable(){
@Override
public void run() {
ksession.fireUntilHalt();
}
});
t.start();
for (float x = 0.0f; x < 20.0f; x++){
DataReading dr = new DataReading("Reading " + x, x);
myStream.insert(dr);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws
Exception {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse
knowledge.");
}
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
With the following rule in the sample.drl file:
package com.sample
import com.sample.DroolsTest.Message;
import java.util.Date;
declare DataReading
@role( event )
end
rule "MyGuidedRule"
dialect "mvel"
when
$dr: DataReading( reading > "10.0" ) from
entry-point "My Stream"
then
System.err.println("Reading: " + $dr.name
+ " > 10.0 " +
System.currentTimeMillis());
end
know I am running fireUntilHalt on a seperate thread as you
can see, but
events injected fire rules out of order...in fact almost the
exact
opposite order in which they were inserted to the stream every
time:
Reading: Reading 19.0 > 10.0 1311325346490
Reading: Reading 18.0 > 10.0 1311325346491
Reading: Reading 17.0 > 10.0 1311325346491
Reading: Reading 16.0 > 10.0 1311325346491
Reading: Reading 15.0 > 10.0 1311325346491
Reading: Reading 14.0 > 10.0 1311325346491
Reading: Reading 13.0 > 10.0 1311325346491
Reading: Reading 12.0 > 10.0 1311325346491
Reading: Reading 11.0 > 10.0 1311325346491
I want to eventually perform temporal reasoning, but how can I
expect
that to work if events are not evaluated in the order they
were inserted.
Perhaps I am setting up my session/kb improperly?
Thanks,
Chris
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users