7 Replies Latest reply on Mar 29, 2007 4:36 AM by avbentem

    spawning workflow from action handler Q

    fmuhlenberg

      I have a workflow that initially executes a common set of nodes but then diverges to one of about 10 different complicated paths. I am looking for advice on a reasonable way to handle this.

      My thought is to break up the full workflow into a common primary workflow and divergent secondary workflows. This would help maintenence. Anyway, after a decision, I would instantiate and run the secondary workflow but I don't see any simple way to do this from an ActionHandler. Is there an easy way to do this or do I just need to bite the bullet and either pass in or obtain another JbpmSession?
      -fm

        • 1. Re: spawning workflow from action handler Q
          aguizar

          Why do you need to spawn a workflow from an action handler? Process states are designed just for that purpose. If you really have to do it, the implementation of org.jbpm.graph.node.ProcessState.execute() will help you.

          • 2. Re: spawning workflow from action handler Q
            aguizar

            I was in Reston for a public jBPM training last year. Beatiful place :-) A bit cold for my taste, tough.

            • 3. Re: spawning workflow from action handler Q
              tom.baeyens

              alex,

              indeed, the process-state is the main use case for process composition.

              but there are 2 other possibilities that make sense and that we didn't implement yet. the process state synchronizes on the end of the process instance. you might want to launch a new process instance without waiting for it to end. one possibility is to do this from a node (e.g. by adding a kind of 'dontwait' attribute to the process-state). or from an action.

              regards, tom.

              • 4. Re: spawning workflow from action handler Q
                brianmb99

                Hi fm,

                I have a similar workflow scenario and I use this code in an ActionHandler:

                JbpmSession sess = JbpmSession.getCurrentJbpmSession();
                GraphSession gs = sess.getGraphSession();
                ProcessDefinition newprocessDef = gs.findLatestProcessDefinition(newprocessname);
                if (newprocessDef == null) return;
                ProcessInstance subprocess = new ProcessInstance(newprocessDef);
                newprocess.signal();


                Is that what you're looking to do? It all runs within the current session this way. I manage the relationship between the new/subprocesses and the parent/superprocesses through mechanisms outside the jBPM super/sub mechanism.

                I tried dynamically using subprocesses from a process-state node but couln't get it to work (http://www.jboss.com/index.html?module=bb&op=viewtopic&t=76444).

                -Brian

                • 5. Re: spawning workflow from action handler Q
                  fmuhlenberg

                  Brian,
                  I did realize I could instantiate a process the same way I already had but for some unfathomable reason, I was trying to avoid the call to JbpmSession.getCurrentJbpmSession(). Your suggestion will work for what I want.

                  Alex,
                  Reston is nice and will be warming up next weekend and spring is coming.

                  What I really want to do when I reach my particular node is dynamically append to my existing process instance, then transition along that new path until completion.

                  Tom, et al,
                  Would it make any sense to be able to this? Provide a process instance append method that accepts the workflow. The transitions from the new workflow?s start node become the departing transitions from the current node. The read in workflow?s end node would remap to the current process instance?s end node.

                  Or is this already existing functionality that I am completely overlooking or something that workflow shouldn't be doing?
                  -fm

                  • 6. Re: spawning workflow from action handler Q
                    enazareno

                    Hi fmuhlenberg,

                    What I really want to do when I reach my particular node is dynamically append to my existing process instance, then transition along that new path until completion.


                    Have you tried creating child Tokens from your main process and referencing it to the sub process that you will create? To create a child token, you can use

                    Token t = new Token( mainProcess.getRootToken(), tokenName)

                    To reference it from the sub process created, set this token in the setSuperProcessToken. You can then signal the parent process from the sub process using getSuperProcessToken().signal. However, if you implement multiple sub processes, I guess you have to implement a fork-join in your parent process.

                    Regards,

                    Elmo

                    • 7. Re: spawning workflow from action handler Q

                       

                      "brianmb99" wrote:
                      I tried dynamically using subprocesses from a process-state node but couln't get it to work (http://www.jboss.com/index.html?module=bb&op=viewtopic&t=76444).

                      Maybe things were different in the 3.0.2 version of jBPM you were using back then, but in 3.2.Beta2 the following really works just fine (also without the binding attribute):
                      <process-state name="My sub-process">
                       <sub-process name="my-sub-process" binding="late"/>
                       <transition name="" to="Done"></transition>
                      </process-state>

                      Arjan.