10 Replies Latest reply on Jan 14, 2009 4:11 AM by Olivier Debels

    ProcessInstance ending changed

    Olivier Debels Newbie

      I am updating from an older version (3.1.4) to the latest jbpm version (3.3.0.GA).

      I saw that the method end(boolean reativeSuper) was removed. This is breaking some of our unit tests.

      We have scenario's where we want to stop child tokens of a process instance without activating the parent. This means really aborting the process instance and not continuing any more.

      Before when calling token.end(false), this would call processInstance.end(false), which would not reactivate the parent token.

      Now this reactivates the parent token, so the parent process instance continues.

      What was the reason behind this breaking change?

        • 1. Re: ProcessInstance ending changed
          Ronald van Kuijk Master

          I just checked the code and token.end(boolean verifyParentTermiation) is still there.... So either I miss something or there is something wrong in your unittest ;-)

          • 2. Re: ProcessInstance ending changed
            Olivier Debels Newbie

            You missed something ;-)

            I was talking about ProcessInstance#end(boolean reactivateSuper) which is no longer there...

            Token#end(boolean verifyParentTermination) used this method before...

            • 3. Re: ProcessInstance ending changed
              Ronald van Kuijk Master

              Hmmmmm ProcessInstance#end(boolean reactivateSuper) sounds a bit weird to me... So I can imagine it was removed. Can you describe the usecase for this? Does it have something to do with subprocesses which you want to end but not have it signal the parent process?

              What if you woud do change

              processInstance.end(false)


              to

              processInstance.getRootToken().end(false)



              • 4. Re: ProcessInstance ending changed
                Olivier Debels Newbie

                Indeed it has to do with the subprocess which signals the parent process in the current implementation, and did not do that in the previous implementation.

                In our case we have a process with a root token and some child tokens. The child tokens have a sub process.

                When ending a child token, it should stop directly.

                Now when we call childToken#end(false), subProcessInstance#end() will be called. This will reactivate the super token which we don't want.

                Before childToken#end(false), called subProcessInstance#end(false) which did not reactivate the super token...

                • 5. Re: ProcessInstance ending changed
                  Ronald van Kuijk Master

                  ahh... ok it is signalling 'downwards' not upwards which you want not to happen if I interpret this correctly.

                  But what do you mean then by

                  When ending a child token, it should stop directly.


                  Should I read this as

                  "If we cancel a childtoken on the main process, it (the childtoken) should stop but te subprocess should continue.

                  Sounds a bit weird to me then, cancelling a childtoken but leaving the subprocess running

                  • 6. Re: ProcessInstance ending changed
                    Olivier Debels Newbie

                     

                    ahh... ok it is signalling 'downwards' not upwards which you want not to happen if I interpret this correctly.


                    No, it's the upwards signalling I want to prevent. Sub process instances when canceled, signal their "superProcessToken"

                    "If we cancel a childtoken on the main process, it (the childtoken) should stop but te subprocess should continue


                    No, the sub process should stop immediately. And not trigger the continuation of its parent token as is happening right now.

                    • 7. Re: ProcessInstance ending changed
                      Ronald van Kuijk Master

                      hmm..... do you have a small unit test because I think the 'workaround' I mentioned should work

                      • 8. Re: ProcessInstance ending changed
                        Olivier Debels Newbie

                        Here is a unit test.

                        When aborting a child token, the child token is triggered to go to the next node (task node).

                        So we create an additional task instance. Something we certainly don't want when aborting the token.

                        public class AbortTokenTest {
                        
                         public static final String MAIN_PROCESS =
                         "<process-definition name='MainProcess'>" +
                         " <start-state>" +
                         " <transition to='fork' />" +
                         " </start-state>" +
                         " <fork name='fork'>" +
                         " <transition name='transition1' to='subProcess1' />" +
                         " <transition name='transition2' to='subProcess2' />" +
                         " </fork>" +
                         " <process-state name='subProcess1'>" +
                         " <sub-process name='SubProcess'/>" +
                         " <transition to='taskNode1' />" +
                         " </process-state>" +
                         " <task-node name='taskNode1'>" +
                         " <task name='generic' />" +
                         " <transition to='join' />" +
                         " </task-node>" +
                         " <process-state name='subProcess2'>" +
                         " <sub-process name='SubProcess'/>" +
                         " <transition to='taskNode2' />" +
                         " <task-node name='taskNode2'>" +
                         " <task name='generic' />" +
                         " <transition to='join' />" +
                         " </task-node>" +
                         " </process-state>" +
                         " <join name='join' lock='UPGRADE'>" +
                         " <transition to='end' />" +
                         " </join>" +
                         " <end-state name='end' />" +
                         "</process-definition>";
                        
                         /**
                         * Process definition with single root token and task node.
                         */
                         public static final String SUB_PROCESS =
                         "<process-definition name='SubProcess'>" +
                         " <start-state>" +
                         " <transition to='taskNode' />" +
                         " </start-state>" +
                         " <task-node name='taskNode'>" +
                         " <task name='generic' />" +
                         " <transition to='end' />" +
                         " </task-node>" +
                         " <end-state name='end' />" +
                         "</process-definition>";
                        
                         private JbpmContext jbpmContext;
                        
                         @Before
                         public void initialize() {
                         jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
                        
                         // Deploy sub process and main process
                         jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlString(SUB_PROCESS));
                         jbpmContext.deployProcessDefinition(ProcessDefinition.parseXmlString(MAIN_PROCESS));
                         }
                        
                         @After
                         public void uninitialize() {
                         jbpmContext.close();
                         }
                        
                         @Test
                         public void cancelToken() {
                         ProcessInstance processInstance = jbpmContext.newProcessInstance("MainProcess");
                         processInstance.signal();
                         assertNull(processInstance.getTaskMgmtInstance().getTaskInstances());
                        
                         // Abort one of the child token's
                         processInstance.getRootToken().getChild("transition1").end(false);
                        
                         // Unit test fails -> a task instance is created in the main process
                         // This because the child token is signalled and is in taskNode1 now...
                         assertNull(processInstance.getTaskMgmtInstance().getTaskInstances());
                         }
                        }


                        • 9. Re: ProcessInstance ending changed
                          Ronald van Kuijk Master

                          I tried this and was able to run it inspite of a small error in your processdefinition (task2 is in the processstate ;-) )

                          You signal the 'child-token' which is in the proces-state node, not in the subprocess itself. So to me ending that does not signal any parent node. It does transition this specific token to the next one. I think that should maybe not happen but still...

                          If you want the subprocess to end and not signal the parent token, then end the rootToken of the subprocess with end(false) like

                          processInstance.getRootToken().getChild("transition1").getSubProcessInstance().getRootToken().end(false);


                          If I adapt the unittest this does exactely what you want
                          ProcessInstance processInstance = jbpmContext.newProcessInstance("MainProcess");
                           processInstance.signal();
                          
                           assertNull(processInstance.getTaskMgmtInstance().getTaskInstances());
                          
                           assertEquals("subProcess1", processInstance.getRootToken().getChild("transition1").getNode().getName());
                          
                           // Abort one of the subprocesses
                           processInstance.getRootToken().getChild("transition1").getSubProcessInstance().getRootToken().end(false);
                          
                           assertNull(processInstance.getTaskMgmtInstance().getTaskInstances());
                           assertTrue(processInstance.getRootToken().getChild("transition1").getSubProcessInstance().getRootToken().hasEnded());
                           assertFalse(processInstance.getRootToken().getChild("transition1").hasEnded());
                           assertEquals("subProcess1", processInstance.getRootToken().getChild("transition1").getNode().getName());
                          


                          • 10. Re: ProcessInstance ending changed
                            Olivier Debels Newbie

                            Indeed,

                            But this keeps the 'child-token' alive. Since we 'play' we child-tokens (like dynamically adding and removing them ;-)), this is something we don't want.

                            However a valid solution for my issue is probably
                            - first end the sub process
                            - afterwards end the 'child-token'

                            So calling an end myself from bottom (sub process in this case) to top (child token in this case).

                            This is some extra work but will due.

                            Thx,

                            Olivier.