<br><div class="gmail_quote">2012/2/8 Esteban Aliverti <span dir="ltr">&lt;<a href="mailto:esteban.aliverti@gmail.com">esteban.aliverti@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

This is a tricky one :)</blockquote><div><br>Indeed it was! ;-)<br><br>I&#39;ve made the changes as sugested and it works like a charm. <br><br>What you say about the process being created and executed *before* the correponding fact is inserted into the session now totally makes sense to me.<br>

<br>Thank you very much!<br><br><br><br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><br></div><div>What is happening is that you are running the process first and inserting the process instance later. </div>

<div>When the process is started, it runs until it finds the Rule Task. At that point, since there is no activation for any of the rules in &quot;jobs group&quot; (there is no ProcessInstance inserted yet, so there is no activation for &quot;job complete&quot; rule) the execution continues (since you are already inside a fireAllRules() invocation) until the process reaches the end or a wait-state. At that point, the control is returned to the original rule that started the process and the ProcessInstance is finally inserted. </div>



<div>What you can do is to split the creation of the process instance and its execution: </div><div><br></div><div><div><div><div class="im">rule &quot;New case&quot; <br>    when    <br>        $case : Case(processed==false) from entry-point &quot;case stream&quot;        <br>



    then<br>        modify ($case){<br>            setProcessed(true)<br>        }<br>  <br>        [....  processing code omitted ... ]<br><br></div>        //create the instance, but don&#39;t start it yet<br>        ProcessInstance processInstance = kcontext.getKnowledgeRuntime().createProcessInstance(&quot;com.mycompany.Process&quot;, parameters);</div>



<div><br></div><div>        //insert the instance in the WM: this will create the activation of the other rule<br>        insert(processInstance);</div><div><br></div><div>        //now, start the process</div>

<div>        kcontext.getKnowledgeRuntime().startProcessInstance(processInstance.getProcessInstance());</div><div><br></div></div><div><div><div>end</div></div></div></div><div>

<br></div><div>Best Regards,</div><div><br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>- Developer @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com </a><br>- Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>




<br><br><div class="gmail_quote">2012/2/8 Alberto R. Galdo <span dir="ltr">&lt;<a href="mailto:argaldo@gmail.com" target="_blank">argaldo@gmail.com</a>&gt;</span><div><div class="h5"><br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<div><div>I&#39;m afraid I can&#39;t publish as it is, but I hope this would give you a hint:<br><br>myrules.drl:<br><br>rule &quot;New case&quot; <br>    when    <br>        $case : Case(processed==false) from entry-point &quot;case stream&quot;        <br>






    then<br>        modify ($case){<br>            setProcessed(true)<br>        }<br>  <br>        [....  processing code omitted ... ]<br><br>        insert(kcontext.</div></div><div><div><div>getKnowledgeRuntime().startProcess(&quot;com.mycompany.Process&quot;, parameters));<br>






end<br><br>rule &quot;job complete&quot;<br>ruleflow-group &quot;jobs group&quot;<br>    when<br>        $processInstance: WorkflowProcessInstance()<br>    then<br>        Job job = (Job)$processInstance.getVariable(&quot;var&quot;);<br>






        update(job);<br>end<br><br><br><br><br>process.bpmn:<br><br>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;definitions ....&gt;<br>&lt;process processType=&quot;Private&quot; isExecutable=&quot;true&quot; id=&quot;com.mycompany.Process&quot; name=&quot;process&quot; &gt;<br>






[one start node and lots of nodes here, one that ends in the next ]<br><br>&lt;businessRuleTask g:ruleFlowGroup=&quot;jobs group&quot; id=&quot;job complete&quot; name=&quot;complete job&quot;/&gt;<br><br>[ lots of nodes after, ending in an end node]<br>






<br>&lt;/process&gt;<br>&lt;/definitions&gt;<br><br><br><br><br>As you 
can see the rule &quot;New case&quot; is not in any group and is responsible ( if 
it is the case ) of launching the process, and then that process invokes
 the bussinessrule group &quot;jobs group&quot;. As stated, what we see is that 
the rule &quot;job complete&quot; never gets fired.<br>
<br><br><br clear="all">Alberto R. Galdo<br></div></div><a href="mailto:argaldo@gmail.com" target="_blank">argaldo@gmail.com</a><br><br></div><br clear="all">Alberto R. Galdo<br><a href="mailto:argaldo@gmail.com" target="_blank">argaldo@gmail.com</a><div>



<div><br>

<br><br><br><div class="gmail_quote">On Tue, Feb 7, 2012 at 21:16, Mauricio Salatino <span dir="ltr">&lt;<a href="mailto:salaboy@gmail.com" target="_blank">salaboy@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div>&quot;&quot;businessRuleTask&quot; who tries to fire a rule in drools ant that rule<br>
</div>are not in the same group&quot; can you share the process definition and<br>
the rule?<br>
<br>
2012/2/7 Alberto R. Galdo &lt;<a href="mailto:argaldo@gmail.com" target="_blank">argaldo@gmail.com</a>&gt;:<br>
<div><div>&gt; Hi,<br>
&gt;<br>
&gt;    The rule that inserts the process which has the node &quot;businessRuleTask&quot;<br>
&gt; who tries to fire a rule in drools ant that rule are not in the same group.<br>
&gt; In fact, the rule that should be fired is the only rule in that group and<br>
&gt; should only be fired by the process itself.<br>
&gt;<br>
&gt;    What we are trying to do is to update the state of a fact inside drools<br>
&gt; with information gathered in the BPM process. Maybe I am getting this wrong,<br>
&gt; but, Is there another way to accomplish this?<br>
&gt;<br>
&gt; Greets,<br>
&gt;<br>
&gt;<br>
&gt; Alberto R. Galdo<br>
&gt; <a href="mailto:argaldo@gmail.com" target="_blank">argaldo@gmail.com</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Feb 7, 2012 at 19:23, Mauricio Salatino &lt;<a href="mailto:salaboy@gmail.com" target="_blank">salaboy@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi are you using the same rule flow-group in the businessRuleTask and<br>
&gt;&gt; in your rule? can you share the rule that you are using?<br>
&gt;&gt; remember that the evaluation will be done by the engine as soon as the<br>
&gt;&gt; information comes in. The rule flow group will only execute something<br>
&gt;&gt; if a rule was activated inside the rule flow group of your<br>
&gt;&gt; businessRuleTask.<br>
&gt;&gt; Cheers<br>
&gt;&gt;<br>
&gt;&gt; On Tue, Feb 7, 2012 at 2:23 PM, argaldo &lt;<a href="mailto:argaldo@gmail.com" target="_blank">argaldo@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; Hi,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;  We&#39;re running an application that uses Drools + JBPM 5 + Drools<br>
&gt;&gt; &gt; integration our set-up can be seen as:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;  Some rule fires and creates a JBPM process ( a fact gets inserted into<br>
&gt;&gt; &gt; drools using &quot;kcontext.getKnowledgeRuntime().startProcess()&quot; ), after a<br>
&gt;&gt; &gt; few<br>
&gt;&gt; &gt; nodes processed, the JBPM engine arrives to a node of type<br>
&gt;&gt; &gt; &quot;businessRuleTask&quot; which in turn tells drools to evaluate a group of<br>
&gt;&gt; &gt; rules (<br>
&gt;&gt; &gt; which at the moment consists on only one rule ).<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;  Well, the problem is that what we see is that everything runs ok before<br>
&gt;&gt; &gt; the businessRuleTask and at the moment when the rule group would be<br>
&gt;&gt; &gt; evaluated we could see that in drools the rule gets created, activated,<br>
&gt;&gt; &gt; but<br>
&gt;&gt; &gt; never fired.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;  We did some debug and realized that the reason the rule group never got<br>
&gt;&gt; &gt; fired is because this check in RuleFlowGroupImpl.java ( method<br>
&gt;&gt; &gt; setActive(boolean) ):<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;            if ( this.list.isEmpty() ) {<br>
&gt;&gt; &gt;                if ( this.autoDeactivate ) {<br>
&gt;&gt; &gt;                    // if the list of activations is empty and<br>
&gt;&gt; &gt;                    // auto-deactivate is on, deactivate this group<br>
&gt;&gt; &gt;                    WorkingMemoryAction action = new DeactivateCallback(<br>
&gt;&gt; &gt; this );<br>
&gt;&gt; &gt;                    this.workingMemory.queueWorkingMemoryAction( action<br>
&gt;&gt; &gt; );<br>
&gt;&gt; &gt;                }<br>
&gt;&gt; &gt;            }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;   The problem is that at the moment when drools calls setActive() and<br>
&gt;&gt; &gt; performs the check, this.list is in fact empty and autoDeactivate is<br>
&gt;&gt; &gt; true by<br>
&gt;&gt; &gt; default ). Then drools enqueues a deactivation task afterwords, which<br>
&gt;&gt; &gt; deactivates the rule *before* even firing it.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    From now on, things get a little weirder, every subsequent invocation<br>
&gt;&gt; &gt; of<br>
&gt;&gt; &gt; the method setActive ( in response of bussinessRuleTask from our<br>
&gt;&gt; &gt; bussiness<br>
&gt;&gt; &gt; process ) runs ok as that list now is not empty ( has one rule ).<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;    Seems a race condition to me, but,...,  Is there any way to<br>
&gt;&gt; &gt; deactivate<br>
&gt;&gt; &gt; autodeactivation by default? Are we doing something wrong? Bug report?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Greets,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; --<br>
&gt;&gt; &gt; View this message in context:<br>
&gt;&gt; &gt; <a href="http://drools.46999.n3.nabble.com/Rule-does-not-fire-when-JBPM-asks-to-do-so-in-BPMN-2-0-process-tp3723183p3723183.html" target="_blank">http://drools.46999.n3.nabble.com/Rule-does-not-fire-when-JBPM-asks-to-do-so-in-BPMN-2-0-process-tp3723183p3723183.html</a><br>






&gt;&gt; &gt; Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt;  - CTO @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com</a><br>
&gt;&gt;  - MyJourney @ <a href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><br>
&gt;&gt;  - Co-Founder @ <a href="http://www.jugargentina.org" target="_blank">http://www.jugargentina.org</a><br>
&gt;&gt;  - Co-Founder @ <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br>
&gt;&gt;<br>
&gt;&gt;  - Salatino &quot;Salaboy&quot; Mauricio -<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
<br>
<br>
<br>
--<br>
 - CTO @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com</a><br>
 - MyJourney @ <a href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><br>
 - Co-Founder @ <a href="http://www.jugargentina.org" target="_blank">http://www.jugargentina.org</a><br>
 - Co-Founder @ <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br>
<br>
 - Salatino &quot;Salaboy&quot; Mauricio -<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</div></div></blockquote></div><br>
</div></div><br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></blockquote></div></div></div><br></div>
<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>
<br></blockquote></div><br>