6 Replies Latest reply on May 8, 2007 11:02 AM by avivstav

    Interaction between two actors

    avivstav

      Hi
      I am quite new to JBPM, and I need to cordinate between two seperate Threads using JBPM,
      Suppose using the first example flow from the start-kit:

       <process-definition>
       <start-state>
       <transition to='s' />
       </start-state>
       <state name='s'>
       <transition to='end' />
       </state>
       <end-state name='end' />
       </process-definition>
      


      I want to start the flow from the main thread and move to state 's' by using signal(), then I want another seperate thread to get the process definition id
      (for this case suppose I save it in global place) and signal the first thread to move on the flow, is it possible?
      From the test I did the main thread never wait() for signal when entered a new state.


        • 1. Re: Interaction between two actors
          avivstav

          Should I signal the main thread upon operation done by the second thread? In that case I should use callback or any other mechanism, and continue from the state moved by the signal, am I right?

          • 2. Re: Interaction between two actors

            Dan,

            The short answer is: it will work.

            You've fallen into a common newbie wrong-thought.

            Imagine that a deployment has a million processes running, but steps only happen once a day. A workflow engine that ran a separate Java thread for each process would be a pig.

            So instead, engines are always event-based. You'll never see one go into a wait() state for a particular process. Instead, when a process blocks waiting for an external event, the state is persisted.

            When the event happens, it restores the process state and continues.

            I've simplified the following:
            - processes can fork and be in more than one state at the same time.
            - the persistence behavior is a little more complicated.
            See the userguide for more.

            -Ed Staub

            • 3. Re: Interaction between two actors
              avivstav

              Hi
              I understand the point but in chapter 9 in JBPM tutorial http://docs.jboss.com/jbpm/v3/userguide/processmodelling.html
              section 9.3.1 they talk about node responsibilitiesto propagate the execution,

              1. not propagate the execution. In that case the node behaves as a wait state.
              2. propagate the execution over one of the leaving transitions of the node. This means that the token that originally arrived in the node is passed over one of the leaving transitions with the API call executionContext.leaveNode(String). The node will now act as an automatic node in the sense it can execute some custom programming logic and then continue process execution automatically without waiting.


              So what is it refers to?

              • 4. Re: Interaction between two actors

                When you say wait(), do you mean java.lang.Object.wait()?

                If so, then you didn't understand my point.
                It will work.
                Try it, walk it with the debugger, and you'll understand.

                If not, sorry, I misunderstood your question.

                -Ed Staub

                • 5. Re: Interaction between two actors
                  avivstav

                  Hi
                  Yes from the quote I got the understanding that it act as java.wait(),
                  but I realize it's not so, and indeed it after signal() it saves the state to database,
                  Then when I get the event I load the process from DB using the process definition id and continue on with the flow,
                  somehow now I have another strange problem that one sognal call all states in flow,



                  <?xml version="1.0" encoding="UTF-8"?>
                  
                  <process-definition name="Submits New Support Request">
                  
                   <start-state name="create explicit direct call">
                   <transition to="wait for expert to pick up call">
                   <action name="startCallAction" config-type="bean"
                   class="org.springmodules.workflow.jbpm31.JbpmHandlerProxy">
                   <targetBean>requestDirectSupportActionHandler</targetBean>
                   <factoryKey>jbpmConfiguration</factoryKey>
                   </action>
                   </transition>
                   </start-state>
                  
                  
                   <state name='wait for expert to pick up call'>
                   <event type="node-enter">
                   <action name="waitToPickup"
                   class="com.supportspace.stargate.service.impl.jbpm.action.ExpertPickupCallActionHandler"/>
                   </event>
                   <transition name="accept" to="supporter accept call" />
                   <transition name="decline" to="supporter decline call" />
                   <transition name="ignore" to="supporter ignore call" />
                   </state>
                  
                   <state name='supporter accept call'>
                   <event type="node-enter">
                   <script>System.out.println("++++++++++++++ supporter accept call....")</script>
                   </event>
                   <transition to='supporter decline call' />
                   </state>
                  
                  
                   <state name='supporter decline call'>
                   <event type="node-enter">
                   <script>System.out.println("---------------- Supporter Declien call....")</script>
                   </event>
                   <transition to='supporter ignore call' />
                   </state>
                  
                   <state name='supporter ignore call'>
                   <event type="node-enter">
                   <script>System.out.println(">>>>>>>>>>>>>>>>>>> upporter reject call....")</script>
                   </event>
                   <transition to='end' />
                   </state>
                  
                  
                   <end-state name='end'>
                   <event type="node-enter">
                   <script>System.out.println(">>>>>>>>>>>>>>>>>>> Customer recives support ack and end session")</script>
                   </event>
                   </end-state>
                  </process-definition>
                  


                  After the first signal I see all System.out messages,


                  • 6. Re: Interaction between two actors
                    avivstav

                    I think I understand the problem,
                    I bound the action of the start-state inside transition action.
                    10x for your help and support