This is a tricky one :)

What is happening is that you are running the process first and inserting the process instance later. 
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 "jobs group" (there is no ProcessInstance inserted yet, so there is no activation for "job complete" 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. 
What you can do is to split the creation of the process instance and its execution: 

rule "New case" 
    when    
        $case : Case(processed==false) from entry-point "case stream"        
    then
        modify ($case){
            setProcessed(true)
        }
  
        [....  processing code omitted ... ]

        //create the instance, but don't start it yet
        ProcessInstance processInstance = kcontext.getKnowledgeRuntime().createProcessInstance("com.mycompany.Process", parameters);

        //insert the instance in the WM: this will create the activation of the other rule
        insert(processInstance);

        //now, start the process
        kcontext.getKnowledgeRuntime().startProcessInstance(processInstance.getProcessInstance());

end

Best Regards,

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


2012/2/8 Alberto R. Galdo <argaldo@gmail.com>
I'm afraid I can't publish as it is, but I hope this would give you a hint:

myrules.drl:

rule "New case"
    when   
        $case : Case(processed==false) from entry-point "case stream"       
    then
        modify ($case){
            setProcessed(true)
        }
 
        [....  processing code omitted ... ]

        insert(kcontext.
getKnowledgeRuntime().startProcess("com.mycompany.Process", parameters));
end

rule "job complete"
ruleflow-group "jobs group"
    when
        $processInstance: WorkflowProcessInstance()
    then
        Job job = (Job)$processInstance.getVariable("var");
        update(job);
end




process.bpmn:

<?xml version="1.0" encoding="UTF-8"?>
<definitions ....>
<process processType="Private" isExecutable="true" id="com.mycompany.Process" name="process" >
[one start node and lots of nodes here, one that ends in the next ]

<businessRuleTask g:ruleFlowGroup="jobs group" id="job complete" name="complete job"/>

[ lots of nodes after, ending in an end node]

</process>
</definitions>




As you can see the rule "New case" 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 "jobs group". As stated, what we see is that the rule "job complete" never gets fired.



Alberto R. Galdo
argaldo@gmail.com


Alberto R. Galdo
argaldo@gmail.com




On Tue, Feb 7, 2012 at 21:16, Mauricio Salatino <salaboy@gmail.com> wrote:
""businessRuleTask" who tries to fire a rule in drools ant that rule
are not in the same group" can you share the process definition and
the rule?

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



--
 - CTO @ http://www.plugtree.com
 - MyJourney @ http://salaboy.wordpress.com
 - Co-Founder @ http://www.jugargentina.org
 - Co-Founder @ http://www.jbug.com.ar

 - Salatino "Salaboy" Mauricio -

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users