2011/8/22 Chris Richmond crichm...@referentia.com
Doesn't retracting all objects then inserting new objects cause the rules
to be evaluated for the objects currently in working memory?
Mostly, yes, but rules using just not(something) may not fire again unless
retracting changes it to true.
Do I need to use Stateless instead of Stateful or something?
Both use the same reasoning.
Disposing the old session and creating a new one might be one way of
achieving what you have in mind. Also, adding a pattern with a trigger
fact you can change judiciously might do the trick.
-W
Thanks,
Chris
On 8/19/2011 7:47 PM, Wolfgang Laun wrote:
A condition based on the negated existence quantifier is true when no such
object is in the WM. Once recognized as true, the rule fires, and that's it
until it isn't true any more, which is a sort of rewind for the condition
after which the begin of another period of absence is celebrated with
another firing. Repeated stop-and-go of the rule engine does not influence
this monitoring of truth.
-W
2011/8/20 Chris Richmond crichm...@referentia.com
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. Here is my simple test case.
Two clasess: TestMain and TestObject and rule file Test.drl I have
included below.
It insterts a group of facts at one time, fires the rules, and retracts
all those facts from the stream. I have an event listener on the session,
as you see to verify injections and retractions are occuring.
So the rule fires on the first batch, but on no other batches after
that What gives
Among the Inserttion and retraction events I only see:
A proper object does not exist
One time, during firing rules on the first batch. 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.
What is going on???
TestMain.java *
package com.sample;
import java.util.ArrayList;
import java.util.List;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
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.conf.EventProcessingOption;
import org.drools.event.rule.ObjectInsertedEvent;
import org.drools.event.rule.ObjectRetractedEvent;
import org.drools.event.rule.ObjectUpdatedEvent;
import org.drools.event.rule.WorkingMemoryEventListener;
import org.drools.io.ResourceFactory;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.conf.ClockTypeOption;
import org.drools.runtime.rule.FactHandle;
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
public class TestMain {
@SuppressWarnings(restriction)
public static 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);
ksession.addEventListener(new WorkingMemoryEventListener(){
@Override
public void objectInserted(ObjectInsertedEvent oie) {
System.err.println(Inserted: + oie.toString());
}
@Override
public void objectRetracted(ObjectRetractedEvent arg0) {
System.err.println(Retracted: + arg0.toString());
}
@Override
public void objectUpdated(ObjectUpdatedEvent arg0) {
// TODO Auto-generated method stub
}
});
for (int a = 0; a 1000; a++){
ListFactHandle factHandles = new ArrayListFactHandle();
for (int x = 0; x 6; x++){
double reading = 11.3;
float f = (float)reading;
TestObject dr = new TestObject(Reading + x, f);
FactHandle fh = myStream.insert(dr);
factHandles.add(fh);
}
ksession.fireAllRules();
for(FactHandle fh : factHandles){
myStream.retract(fh);
}
Thread.sleep(4000);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@SuppressWarnings(restriction)
private static KnowledgeBase readKnowledgeBase() throws Exception {