<br>   Richard,<br><br>   There are some misconceptions in your example. I will try to clarify some things:<br><br>1. The Ruleflow: every time you call &quot;ksession.startProcess(&quot;myflow&quot;);&quot;, you start a new flow instance (or process instance if you prefer). For each instance, it will activate in turn your groups one, two and three, moving to the next group when no more activations exist. Although, you didn&#39;t tie you facts/rules to any particular instance, meaning you have a &quot;pool of facts&quot; and a &quot;pool of flow instances&quot; that are all matching themselves in no specific way. In other words, you are inserting messages and starting flows 50 times in your example. Imagine that when the flow instance #20 reaches node &quot;three&quot;, you are at the same time inserting message #30... message number #30 will activate the rule &quot;NotThree&quot; and it will fire as part of the flow instance #20... you will have your &quot;strange&quot; behaviors.<br>
<br>2. On top of the situation above, you are firing rules with fireUntilHalt(), meaning the engine is running in asynchronous, reactive mode, and you will have no control at all over the results you are getting back.<br>
<br>3. Since you mentioned fusion on the subject of this message, I guess you are probably setting the message role as &quot;event&quot;, and in stream mode, the engine will try to determine when a fact is no longer needed and can be automatically expired. Although, at the same time, you are trying to retract the event in rules of group &quot;three&quot;. Since the fact might have been already expired by that time, you are getting the consequence exception saying the fact is no longer in the working memory.<br>
<br>   I guess what I am saying is: all these features in Drools are there for a reason, and it is possible to mistakenly try to use them for things they are not intended to. The only way to prevent that is by educating users. If the documentation is not clear, please help us make it better. <br>
<br>   Back to your example, first things first: simplify it... <br><br>* do you really need the engine to run it in reactive mode? try batching facts and fire rules in a more controlled manner. Single thread is, as you know, a lot easier to deal with than multi-threads.<br>
<br>* do you need to have all your events in the same session? If you can have one session per &quot;request&quot;, your flow+rules+events will work as you expect. If you need to have all events and flow and rules in the same session, then you need to tie rules to flow instances using process variables, possibly also using goal facts to drive your progress, etc.<br>
<br>* do you really need events and stream mode? cloud mode (default) is much easier to understand and deal with, since there is no automatic garbage collection, session clock requirements, etc.<br><br>   Hope it helps,<br>
       Edson<br><br><div class="gmail_quote">2009/12/17 RichardA <span dir="ltr">&lt;<a href="mailto:Richard.Ambridge@sun.com">Richard.Ambridge@sun.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi all again,<br>
I am having a problem where the results of the rules is not consistent.<br>
I am using rules flow and fireUntilHalt..<br>
<br>
Here is most of my code: (expanding the default drools example)<br>
<br>
private static KnowledgeBase readKnowledgeBase() throws Exception {<br>
                KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();<br>
                kbuilder.add(ResourceFactory.newClassPathResource(&quot;Sample.drl&quot;),<br>
ResourceType.DRL);<br>
                kbuilder.add(ResourceFactory.newClassPathResource(&quot;Flow.rf&quot;),<br>
ResourceType.DRF);<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>
                KnowledgeBaseConfiguration conf =<br>
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();<br>
                conf.setOption(EventProcessingOption.STREAM);<br>
                KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(conf);<br>
                kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());<br>
                return kbase;<br>
        }<br>
<br>
public static final void main(String[] args) {<br>
                try {<br>
                        // load up the knowledge base<br>
                        KnowledgeBase kbase = readKnowledgeBase();<br>
                        final StatefulKnowledgeSession ksession =<br>
kbase.newStatefulKnowledgeSession();<br>
                        new Thread(new Runnable() {<br>
              public void run() {<br>
                          ksession.fireUntilHalt();<br>
                      }<br>
                    }, &quot;FireAllRules&quot;).start();<br>
                        // go !<br>
                        for(int i=0;i&lt;50;i++){<br>
                          Message message = new Message();<br>
                          message.setMessage(&quot;one&quot;);<br>
                          ksession.insert(message);<br>
                          ksession.startProcess(&quot;myflow&quot;);<br>
                        }<br>
                        System.out.println(&quot;Sleeping&quot;);<br>
                        Thread.sleep(20000);<br>
                        System.out.println(&quot;Halt&quot;);<br>
                        ksession.halt();<br>
                } catch (Throwable t) {<br>
                        t.printStackTrace();<br>
                }<br>
        }<br>
<br>
So, notice fireUntilHalt is started in a thread.<br>
And its in STREAM mode<br>
and I use flow group and sample rules set.<br>
Then inject 50 messages, and after each inject start the &#39;myflow&#39;<br>
<br>
The rule flow is like this;<br>
Start-&gt;  One -&gt; Two -&gt; Three -&gt; End<br>
<br>
and the rules are:<br>
rule &quot;One&quot;<br>
    ruleflow-group &quot;One&quot;<br>
        when<br>
                m : Message( message==&quot;one&quot; )<br>
        then<br>
<br>
                m.setMessage( &quot;two&quot; );<br>
                update( m );<br>
end<br>
<br>
rule &quot;Two&quot;<br>
    ruleflow-group &quot;Two&quot;<br>
        when<br>
                m : Message( message==&quot;two&quot; )<br>
        then<br>
                m.setMessage( &quot;three&quot; );<br>
                update( m );<br>
end<br>
<br>
rule &quot;NotThree&quot;<br>
    ruleflow-group &quot;Three&quot;<br>
        when<br>
                m : Message( message!=&quot;three&quot; )<br>
        then<br>
                System.out.println( &quot;Message is not three????????????&quot; );<br>
                retract(m);<br>
end<br>
rule &quot;Three&quot;<br>
    ruleflow-group &quot;Three&quot;<br>
        when<br>
                m : Message( message==&quot;three&quot; )<br>
        then<br>
                retract(m);<br>
end<br>
<br>
<br>
So, from that you should see that as an object is injected it has<br>
message==&quot;one&quot;<br>
so flow group One should match, the message updates to &#39;two&#39;<br>
then flow group two should match, message updates to &#39;three&#39;<br>
and then the group three rule Three should match and the object retracted.<br>
<br>
Sometimes I run this I get results as expected.<br>
Other times I get 1 message hit the &#39;NotThree&#39; rule.<br>
Other times I get lots of them hit the &#39;NotThree&#39; rule.<br>
Sometimes I get;<br>
Exception in thread &quot;FireAllRules&quot;<br>
org.drools.runtime.rule.ConsequenceException: org.drools.FactException:<br>
Retract error: handle not found for object: null. Is it in the working<br>
memory?<br>
        at<br>
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)<br>
<br>
<br>
Its driving me mad as my project is failing due to inconsistent results.<br>
Please help..<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://n3.nabble.com/Inconsistent-results-in-fusion-tp93259p93259.html" target="_blank">http://n3.nabble.com/Inconsistent-results-in-fusion-tp93259p93259.html</a><br>
Sent from the Drools - User mailing list archive at Nabble.com.<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>
</font></blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>