11 Replies Latest reply on Jul 13, 2007 10:52 AM by kukeltje

    Problem with multiple end-states

    fewagewasd

      Hi,

      I've got a problem with the following test- workflow:

      <process-definition xmlns="" name="test">
       <start-state name="start">
       <transition name="" to="FooBar"></transition>
       </start-state>
       <state name="FooBar">
       <event type="before-signal">
       <action name="check foo bar" class="TestActionHandler"></action>
       </event>
       <transition name="foo" to="EndFoo"></transition>
       <transition name="bar" to="EndBar"></transition>
       </state>
       <end-state name="EndFoo"></end-state>
       <end-state name="EndBar"></end-state>
      </process-definition>
      


      I set a variable, and based on it's value the TestActionHandler calls leaveNode for either the transition "foo" or the transition "bar", which lead to differend end-states. However, the execution ends in the state "EndFoo" every time.
      After the decision the correct transitions are taken, but after entering the EndXX State, the execution doesn't stop, instead another (non-existent)transition to the state EndFoo is taken.

      Here's some of my debug output:
      Token: Token(/)
      Start Time: Tue Jul 10 14:36:40 CEST 2007
      String: action[action[check foo bar]]
      Log Entry: 21
      Token: Token(/)
      Start Time: Tue Jul 10 14:36:40 CEST 2007
      String: node[FooBar]
      Log Entry: 22
      Token: Token(/)
      Start Time: Tue Jul 10 14:36:40 CEST 2007
      String: transition[FooBar-->EndBar]
      Log Entry: 23
      Token: Token(/)
      Start Time: Tue Jul 10 14:36:40 CEST 2007
      String: processinstance[end]
      Log Entry: 24
      Token: Token(/)
      Start Time: Tue Jul 10 14:36:40 CEST 2007
      String: node[EndBar]
      Log Entry: 25
      Token: Token(/)
      Start Time: Tue Jul 10 14:36:40 CEST 2007
      String: transition[EndBar-->EndFoo]
      


      Has someone already experienced this problem, or is it a normal behaviour?

        • 1. Re: Problem with multiple end-states
          kukeltje

          multiple end states are not supported afaik....

          • 2. Re: Problem with multiple end-states
            fewagewasd

            hm if that's the case, i think it shouldn't be allowed by the xml schema to create more than one end state...

            • 3. Re: Problem with multiple end-states

               

              "kukeltje" wrote:
              multiple end states are not supported afaik....


              Ronald,
              Are you sure? Why?

              fewagewasd,

              <event type="before-signal">
               <action name="check foo bar" class="TestActionHandler"></action>
               </event>
              


              You shouldn't call signal or leave-node from an event-handler - do it from an execute action-handler instead. I'm not sure this is the cause of your problem, but it well might be.

              -Ed Staub

              • 4. Re: Problem with multiple end-states
                fewagewasd

                I've tried the following:

                 <node name="node1">
                 <action class="TestActionHandler.class"/>
                 <transition name="foo" to="EndFoo"></transition>
                 <transition name="bar" to="EndBar"></transition>
                 </node>
                


                but i get a DelegationException...

                • 5. Re: Problem with multiple end-states
                  kukeltje

                  yes because in Java you never use the .class extension anywhere

                  • 6. Re: Problem with multiple end-states
                    koen.aers

                    Multiple end-states should work fine. Is there any proof of the contrary?

                    Regards,
                    Koen

                    • 7. Re: Problem with multiple end-states
                      fewagewasd

                      Is there any way to tell jbpm to wait in the state and execute the action when I call signal()?

                      • 8. Re: Problem with multiple end-states
                        kukeltje

                         

                        "estaub" wrote:
                        "kukeltje" wrote:
                        multiple end states are not supported afaik....


                        Ronald,
                        Are you sure? Why?


                        I thought I remembered someone doing this before and not getting it to work, but since Koen says it should work, it might (my AFAIK was added because I was not completely sure)

                        • 9. Re: Problem with multiple end-states
                          efip10

                          I use multiple end-states, and it works.

                          As outlined in "Node responsibilities" in userguide, only the node action can decide on which transition to take. In event action, you cannot take this decision.

                          <node name="check-suspend-or-abort">
                           <action class="com.qq.DecideIfSuspendedOrAbortedAction" />
                           <transition to="continue" />
                           <transition to="error" name="error"/>
                           <transition to="suspended" name="suspended"/>
                           <transition to="aborted" name="aborted"/>
                           </node>
                          
                           <end-state name="aborted">
                           </end-state>
                          
                           <end-state name="suspended">
                           </end-state>
                          
                           <end-state name="error">
                           </end-state>
                          


                          Here's the action:

                          public void execute(ExecutionContext ctx) throws Exception {
                           Map params = ctx.getContextInstance().getVariables();
                          
                           // check if aborted - invoke my function
                           if (isAbortedFlagForWorkflow()) {
                           // do something
                           ctx.getToken().signal("aborted");
                           } else
                           // check if suspended
                           if (isSuspendedFlagForWorkflow()) {
                           // do something
                           ctx.getToken().signal("suspended");
                           } else {
                           // everything is OK, we may start the workflow
                           // leave over default transition
                           ctx.getToken().signal();
                           }
                           }
                          


                          Hope it helps.

                          • 10. Re: Problem with multiple end-states
                            efip10

                             

                            "fewagewasd" wrote:
                            Is there any way to tell jbpm to wait in the state and execute the action when I call signal()?


                            If the action on your node (the main node action, not the event action) does not call token.signal(), then the execution will not propagate. The instance will "wait in the state" until you call signal() again. When you call signal() again, you have to notify which transition to take, e.g. signal("error").

                            If you'd rather have your code make the decision, introduce another node in the flow - after your wait-state node - and make the decision in its main action. This way, when you call signal(), you always take the only transition to a new node, and there its action will decide where to go.


                            • 11. Re: Problem with multiple end-states
                              kukeltje

                              Depending on what the action is or should do, you could use an action on an event of type 'node-leave'