4 Replies Latest reply on May 29, 2008 6:25 AM by waltertaus

    Trying to implement a loop in JPDL

    waltertaus

      Hello,

      I have tried to implement a loop in JPDL. My source looks as follows

      <?xml version="1.0" encoding="UTF-8"?>
      <process-definition xmlns="" name="Pool">
      <start-state name="StartState1212041906165">
      <transition to="LoopBefore3/LoopBefore3LoopCounterInit"></transition>
      </start-state>
      <super-state name="LoopBefore3">
      <node name="LoopBefore3LoopCounterInit">
      <event type="node-enter">
      <script><expression>
      System.out.println(executionContext.getNode().getName() + " entered");
      executionContext.setVariable("_f5Ue8CyoEd2cO4xcRmnV4wLoopCounter", 0);
      executionContext.leaveNode();
      </expression></script></event>
      <transition name="To_f5Ue8CyoEd2cO4xcRmnV4w" to="LoopBefore3LoopDecision"></transition>
      </node>
      <decision name="LoopBefore3LoopDecision">
      <event type="node-enter">
      <script><expression>
      System.out.println(executionContext.getNode().getName() + " entered");
      </expression></script></event>
      <transition name="To_f5Ue8CyoEd2cO4xcRmnV4w" to="LoopBefore3"></transition>
      <transition name="To_mTMyICyoEd2cO4xcRmnV4w" to="../End/End">
      <condition expression="#{contextInstance.variables['_f5Ue8CyoEd2cO4xcRmnV4wLoopCounter']>= '3'}"></condition>
      </transition>
      </decision>
      <task-node name="LoopBefore3">
      <event type="node-enter">
      <script><expression>
      System.out.println(executionContext.getNode().getName() + " entered");
      executionContext.leaveNode();
      </expression></script></event>
      <event type="node-leave">
      <script><expression>
      executionContext.setVariable("_f5Ue8CyoEd2cO4xcRmnV4wLoopCounter", executionContext.getVariable("_f5Ue8CyoEd2cO4xcRmnV4wLoopCounter") + 1);
      </expression></script></event>
      <transition name="To_f5Ue8CyoEd2cO4xcRmnV4w" to="LoopBefore3LoopDecision"></transition>
      <task name="LoopBefore3"></task>
      </task-node>
      </super-state>
      <super-state name="End">
      <end-state name="End">
      <event type="node-enter">
      <script><expression>
      System.out.println(executionContext.getNode().getName() + " entered");
      </expression></script></event>
      </end-state>
      </super-state>
      </process-definition>
      

      I receive the following at the Console:
      StartState1212041906165
      LoopBefore3LoopCounterInit entered
      LoopBefore3LoopDecision entered
      LoopBefore3 entered
      LoopBefore3LoopDecision entered
      LoopBefore3 entered
      LoopBefore3LoopDecision entered
      LoopBefore3 entered
      LoopBefore3LoopDecision entered
      End entered
      LoopBefore3LoopDecision entered
      End entered
      

      I am totally puzzled with this result, as I am hitting twice the end-state. The first time entering the end state does not seem to have any effect. Can anyone explain what I am doing wrong here.

      Thanks,
      Walter

        • 1. Re: Trying to implement a loop in JPDL
          kukeltje

          you have no real end state, only a basic process and 2 superstates. Could be that there is a 'bug' in jBPM that tries to find an end-state and see's it in the superstate. That is executed once because it is a superstate node and maybe once more because it is seen as *the* end state. See what happens if you have a real end-state or remove the superstate around the end-state

          btw, why this construction with the superstate around the end-state

          • 2. Re: Trying to implement a loop in JPDL
            waltertaus

            I have removed the super-state around the end-state (and there is no real need for it), but the result is still the same.
            What do you mean with "real end state"?

            Thanks,
            Walter

            • 3. Re: Trying to implement a loop in JPDL
              kukeltje

              real end state was 'not an end-state in a super state'. I have no hands-on experience with superstates, so unfortunately not able to help you further

              • 4. Re: Trying to implement a loop in JPDL
                waltertaus

                ven after removal of the super-state around the end-state the behaviour is still the same. So I do not really understand where this invocation of the after having reached the end state comes from.
                Any help on this will be highly appreciated.

                Thanks,
                Walter