[rules-users] Inconsistent results in fusion

RichardA Richard.Ambridge at sun.com
Thu Dec 17 09:51:01 EST 2009


Hi all again,
I am having a problem where the results of the rules is not consistent.
I am using rules flow and fireUntilHalt..

Here is most of my code: (expanding the default drools example)

private static KnowledgeBase readKnowledgeBase() throws Exception {
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
ResourceType.DRL);
		kbuilder.add(ResourceFactory.newClassPathResource("Flow.rf"),
ResourceType.DRF);
		KnowledgeBuilderErrors errors = kbuilder.getErrors();
		if (errors.size() > 0) {
			for (KnowledgeBuilderError error: errors) {
				System.err.println(error);
			}
			throw new IllegalArgumentException("Could not parse knowledge.");
		}
		KnowledgeBaseConfiguration conf =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
		conf.setOption(EventProcessingOption.STREAM);
		KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(conf);
		kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
		return kbase;
	}

public static final void main(String[] args) {
		try {
			// load up the knowledge base
			KnowledgeBase kbase = readKnowledgeBase();
			final StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
			new Thread(new Runnable() {
              public void run() {
		          ksession.fireUntilHalt();
		      }
		    }, "FireAllRules").start();
			// go !
			for(int i=0;i<50;i++){
			  Message message = new Message();
			  message.setMessage("one");
			  ksession.insert(message);
			  ksession.startProcess("myflow");
			}
			System.out.println("Sleeping");
			Thread.sleep(20000);
			System.out.println("Halt");
			ksession.halt();
		} catch (Throwable t) {
			t.printStackTrace();
		}
	}

So, notice fireUntilHalt is started in a thread.
And its in STREAM mode
and I use flow group and sample rules set.
Then inject 50 messages, and after each inject start the 'myflow'

The rule flow is like this;
Start->  One -> Two -> Three -> End

and the rules are:
rule "One"
    ruleflow-group "One"
	when
		m : Message( message=="one" )
	then
		
		m.setMessage( "two" );
		update( m );
end

rule "Two"
    ruleflow-group "Two"
	when
		m : Message( message=="two" )
	then		
		m.setMessage( "three" );
		update( m );
end

rule "NotThree"
    ruleflow-group "Three"
	when
		m : Message( message!="three" )
	then
		System.out.println( "Message is not three????????????" ); 
		retract(m);
end
rule "Three"
    ruleflow-group "Three"
	when
		m : Message( message=="three" )
	then		
		retract(m);
end


So, from that you should see that as an object is injected it has
message=="one"
so flow group One should match, the message updates to 'two'
then flow group two should match, message updates to 'three'
and then the group three rule Three should match and the object retracted.

Sometimes I run this I get results as expected.
Other times I get 1 message hit the 'NotThree' rule.
Other times I get lots of them hit the 'NotThree' rule.
Sometimes I get;
Exception in thread "FireAllRules"
org.drools.runtime.rule.ConsequenceException: org.drools.FactException:
Retract error: handle not found for object: null. Is it in the working
memory?
	at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)


Its driving me mad as my project is failing due to inconsistent results.
Please help..

-- 
View this message in context: http://n3.nabble.com/Inconsistent-results-in-fusion-tp93259p93259.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list