12 Replies Latest reply on Jun 8, 2010 10:40 PM by Rachel Hodos

    Subprocess transition in a fork is not working

    Felix Jose Newbie

      Hi All,

       

      I am having a  main JBPM process(helloworld.jpdl.xml) and in that having a fork of that one transition to a sub process and the other to a state node. And these to should transition to a join join1 node.  When I started the process it sucessfully reaching the fork and both two transitions are reached. But As the subprocess contains a state node "printHelloWorld" the execution will wait in that. And meanwhile as the other transition node in the fork is a state node (Being1) it also wait in that node.

      snippet of Main process(helloworld.jpdl.xml)

       

      <fork g="101,278,80,40" name="printHelloWorld">
        <transition g="56,193:-39,-18" name="Being1" to="Being1"/>
        <transition g="137,177:24,8" name="review" to="review"/>
       
      </fork>
      <join g="855,204,80,40" name="join1">
        <transition to="printHelloWorld2"/>
      </join>
           <state name="Being1" g="0,0,80,40">
        <transition to="join1" g="877,666:"/>--------Other execution is active at this node. Waiting for an external signal
      </state>
      <sub-process name="review" sub-process-key="SubProc" g="0,0,80,40">
        <transition to="join1" g="877,666:"/>
      </sub-process>

       

      subporcess (SubPoc.jpdl.xml)

       

      <process name="SubProc" xmlns="http://jbpm.org/4.3/jpdl">
      <start g="372,19,80,40">
        <transition to="printHelloWorld"/>
      </start>
          <state name="printHelloWorld" g="0,0,80,40">------Subprocess execution is waiting in This node. Waiting for an external signal.
        <transition name="printHelloWorld1" to="printHelloWorld1" g="877,666:"/>
      </state>
      <java g="539,206,138,40" method="printHelloWorld" name="printHelloWorld1">
        <transition g="606,516:-39,-18" name="theEnd" to="theEnd"/>
      </java>
      <end g="369,491,80,40" name="theEnd"/>
      </process>

       

      I have used processInstance.getExecutions() which gives the active executions and the result is:

       

      [execution[helloWorld.13.Being1], execution[helloWorld.13.review]]

       

      Then by using openExecutio.getSubProcessInstance().getId(); I find out the subprocess instance id and is [SubProc.21].

       

      Then I signaled the subprocess using executionService.signalExecutionById(id,"printHelloWorld1"); And it sucessfully transitioned and it prints :

      <---------------->

         HELLO FELIX!

      <---------------->

       

      So the subprocess sucessfully completed. But when I check activeactivity name in the subprcess it still shows printHelloWorld state node (by using openExecutio.getSubProcessInstance().findActiveActivityNames()---o/p is --[printHelloWorld])

       

      And also when I checked active executions using processInstance.getExecutions() it still gives:

       

      [execution[helloWorld.13.Being1], execution[helloWorld.13.review]] that means both two forked transitions are in wait state.

       

      So my doubt is how can I transition the subprocess fron one state to another instead of using executionService.signalExecutionById(id,"printHelloWorld1");?

      I have attached the sample application with this. Can you please give a solution as soon as possible?

       

      Thank You and Regards,

      Felix K Jose

        • 1. Re: Subprocess transition in a fork is not working
          Felix Jose Newbie

          Hi All,

           

          Can anybody please give me solution for the same? It is very very urgent. I am expecting some help from you.

           

          Thank You and Regards,

          Felix K Jose

          • 2. Re: Subprocess transition in a fork is not working
            Nikola Vanevski Newbie

            In jBPM 3.X, you can have an ActionHandler that will call

             

            executionContext.leaveNode()

             

            and the token will simply move into next node (end node in your case).

            No need to wait for external signal.

             

            I would presume that similar thing would work in 4.3.

            • 3. Re: Subprocess transition in a fork is not working
              Felix Jose Newbie

              Hi,

               

              Thank you Nikola. But in JBPM 4.3 there is no ActionHandler classes as it in 3.x.

              Other thing is I need an external trigger/signal to transition from one state to another for fulfilling my requirement.

               

              So please anybody send me your thoughts.

               

              Thank You Very Much,

               

              With Regards,

              Felix K Jose

              • 4. Re: Subprocess transition in a fork is not working
                Felix Jose Newbie

                Hi All,

                 

                To whom I have to contact to get a resolution about this? If anybody knows about this please reply to this.

                 

                Thank You very much ,

                Felix Jose

                • 5. Re: Subprocess transition in a fork is not working
                  Maciej Swiderski Master

                  Hi,

                   

                  Felix Jose wrote:

                   

                  And also when I checked active executions using processInstance.getExecutions() it still gives:

                   

                  [execution[helloWorld.13.Being1], execution[helloWorld.13.review]] that means both two forked transitions are in wait state.

                  No, it does not mean that they are both in wait state. You are right when saying that execution [Beaing1] is in wait state since it was not signaled from the beginning. But if it comes to a subprocess that has already been completed and it is ended.

                  You could verify that by looking up for its process instance and check the state of it. In addition, it has already been shown by getting real active activity names in your code.

                   

                  You have two executions because one of them (subprocess) has reached the join activity but it is not yet moved on since it awaits the other forked path. When you look into the the details of that execution you will notice its state 'inactive-join' so as the name indicates it is not active.

                   

                  Conclusion - In my opinion the process works properly. To illustrate this you can take a look at the last lines printed out by your program:

                   

                  System.out.println(processInstance.findActiveActivityNames()); - [Being1]
                  System.out.println(processInstance.getParent()); - null
                  System.out.println(processInstance.getExecutions()); - [execution[helloWorld.13.Being1.18], execution[helloWorld.13.review.19]]
                  

                  Only one activity is active.

                   

                  Felix Jose wrote:


                  So my doubt is how can I transition the subprocess fron one state to another instead of using executionService.signalExecutionById(id,"printHelloWorld1");?

                  In general it depends on the activity type. If you have wait state you should use signal because that's why you have a wait state - to wait for external event to trigger your process. Automatic activities are triggered directly when they are completed. Task activities are triggered on demand by human performing the task.

                   

                  HTH

                   

                  BTW, next time I would recommend you to provide test cases in a form that jBPM recommends it not as a regular java program. Easier to follow for anyone who works with jBPM. And do not include libraries in it, we already have them

                  • 6. Re: Subprocess transition in a fork is not working
                    Felix Jose Newbie

                    Hi Maceij,

                     

                    Thank you very much for the reply.

                     

                    But some issues,

                     

                    if (openExecutio.getSubProcessInstance() != null) {

                                          

                                            String id = openExecutio.getSubProcessInstance().getId();

                                            System.out.println("----id====" + id);

                                            System.out.println("----Active activity Names in Subprocess SubProc.jpdl.xml-----------="+ openExecutio.getSubProcessInstance()

                                                                    .findActiveActivityNames()); //It printed as ----Active activity Names in Subprocess SubProc.jpdl.xml-----------=[printHelloWorld]

                                            //Should Signal it from "printHelloWorld" state node to "printHelloWorld1" java node in the Subprocess SubProc.jpdl.xml

                                            executionService.signalExecutionById(id, "printHelloWorld1");

                    //It is got transitioned and

                                            /* It printed

                                            <---------------->

                                               HELLO FELIX!

                                          <---------------->

                                            */

                                            System.out.println("----Active activity Names in Subprocess SubProc.jpdl.xml-----------="+ openExecutio.getSubProcessInstance().findActiveActivityNames());

                                            //It printed as ----Active activity Names in Subprocess SubProc.jpdl.xml-----------=[printHelloWorld]. Here is the doubt, again the active activity name is get as [printHelloWorld].

                                            System.out.println("State of the subprocess=="+openExecutio.getSubProcessInstance().getState());

                                            //It printed as "State of the subprocess==active-root". That means the subprocess is still active.

                                      }

                     

                     

                    And the at the last lines I am getting some different output from what you got i.e:

                     

                    System.out.println(processInstance.findActiveActivityNames());

                                //It printed as '[Being1, review]'

                    System.out.println(processInstance.getParent());

                                // It printed as 'null'

                    System.out.println(processInstance.getExecutions());

                                // It printed as '[execution[helloWorld.13.Being1], execution[helloWorld.13.review]]'

                     

                    How does it happen?

                    And when I checked state in the suprocesss execution it gives as active-concurrent

                     

                    Can you please help me on the same? And please let me know about this as soon as possible?.

                     

                    Sorry to disturb you...

                     

                    Thank You Very Much,

                     

                    With Regards,

                    Felix Jose

                    • 7. Re: Subprocess transition in a fork is not working
                      Maciej Swiderski Master

                      Felix Jose wrote:


                      And the at the last lines I am getting some different output from what you got i.e:

                       

                      System.out.println(processInstance.findActiveActivityNames());

                                  //It printed as '[Being1, review]'

                      System.out.println(processInstance.getParent());

                                  // It printed as 'null'

                      System.out.println(processInstance.getExecutions());

                                  // It printed as '[execution[helloWorld.13.Being1], execution[helloWorld.13.review]]'

                       

                      How does it happen?

                      Since you made a signal on the subprocess, this will alter the super process as well so you need to look up the process instance once again.

                       

                      processInstance = executionService.findProcessInstanceById(processInstance.getId());
                      

                      When you inspect newly loaded process instance you will get correct info.

                       

                      The same rule applies to getting information about subprocess state. You are checking out of date process instance. Use execution instance returned by signal method.

                      • 8. Re: Subprocess transition in a fork is not working
                        Felix Jose Newbie

                        Hi Maceij,

                         

                        Thanks alot for your reply. I will do whatever you have mentioned in the mail.

                        Once again thank you.

                         

                        With Regards,

                        Felix Jose

                        • 9. Re: Subprocess transition in a fork is not working
                          Felix Jose Newbie

                          Hi Maceij,

                           

                          I have tried and it worked fine. Thank you very much.

                           

                          With Regards,

                          Felix K Jose

                          • 10. Re: Subprocess transition in a fork is not working
                            Rachel Hodos Novice

                            Maciej Swiderski wrote:

                             

                            Since you made a signal on the subprocess, this will alter the super process as well so you need to look up the process instance once again.

                             

                            processInstance = executionService.findProcessInstanceById(processInstance.getId());
                            

                            When you inspect newly loaded process instance you will get correct info.

                             

                            The same rule applies to getting information about subprocess state. You are checking out of date process instance. Use execution instance returned by signal method.

                            This is sort of a tangent, so maybe it should be posted in a separate thread, but I'm just curious why the processInstance needs to be 'refreshed' like this?

                             

                            Thanks,

                            Rachel

                            • 11. Re: Subprocess transition in a fork is not working
                              HuiSheng Xu Master

                              Hi Rachel,

                               

                              Because in jBPM4, all of operations will be done in the Environment. e.g. we invoke findProcessInstanceById(),  jbpm4 will open an environment and open a hibernate session, then do the real cmd, after return result, jbpm4 will close the environment and close relate hibernate session.

                               

                              When we get a process instance or execution from executionService, the instance couldnot automaticly notice when the related record in database being updated.  Because the session of hibernate has been closed.

                               

                              So commonly, after we do some operations likes signal, we should re-get the process instance or execution from executionService, then we could get the real state.  Otherwise what we get will be always the 'OLD' data.

                              • 12. Re: Subprocess transition in a fork is not working
                                Rachel Hodos Novice

                                Thanks for the quick response, HuiSheng.  A related question- I can't find anything in the user guide about when exactly we need to re-get the process instance.  Besides signaling an execution, when else is this necessary?

                                 

                                Rachel