4 Replies Latest reply on Feb 6, 2006 12:53 PM by for Jbpm

    subprocess ? or task-node with *blocking* ?

    for Jbpm Novice

      Hi!

      I need to instantiate external programs in my task-node. I want that process execution is halted till the external program launched, finishes its work. Problem here is that , If I set * blocking* attribute to true It just waits for that external program to be launched.

      How do I achieve this functionality. What's the vision of jbpm (architect) in this scenario. Also there is not much of information regarding *process-state*, *super-state* etc.

      If I use subprocess for my work. Will the parent process wait for a subprocess to finish its execution? I am really not clear about this.

      Any help/ ideas in this regard are highly appreciated!

      Thanks

        • 1. Re: subprocess ? or task-node with *blocking* ?
          Alejandro Guizar Master

          Can I answer even if I'm not the "architect" of jBPM? :-) Alright, why don't you use a state? Upon node-enter, launch the external program, and when it completes, signal the waiting token. If you can't touch the external program to insert the signal at the end, you can wrap it using the java.lang.Process API. In particular, look for the waitFor() method.

          Your question about subprocesses is answered in section 7.7, "process composition" of the jBPM user guide:

          The path of execution of the super process will wait till the sub process instance has ended


          • 2. Re: subprocess ? or task-node with *blocking* ?
            for Jbpm Novice

            oh! Thanks a lot for your quick answer. But problem here is, external program is perl program. I will go through all your suggestions.
            As I didnt get any answer earlier, I started with a different approach. If I am not mistaken signalling token is nothing but changing node_ in *jbpm_token* field to leaving transition node ??? ( here I can get leaving transition from jbpm_task table (if tasknode_ is null Leaving Transition would be startstate_) .
            If from my perl program I change jbpm_token for appropriate for appropriate node_ will that be enough? What else I would have to do in that case?? :-)


            will get back soon! :-)

            • 3. Re: subprocess ? or task-node with *blocking* ?
              Alejandro Guizar Master

              Changing the database directly is not at all advisable, because jBPM will *not* realize you changed the node or "automagically" resume execution from there.

              My suggestion was more along these lines. If your external program is sufficiently short lived, you can wait synchronously for it to finish. In this case you won't release the resources you have allocated (jBPM objects, JDBC connection). Use a node instead of a state and use this as the node action:

              public void execute(ExecutionContext exeContext) throws Exception {
               // execute external program
               Process p = Runtime.exec("yourprogram");
               // wait for the program to terminate
               p.waitFor();
               // resume the process
               exeContext.leaveNode();
              }

              If your program takes a long time to finish, you can use a separate thread in a non-managed environment or a message-driven bean in a managed environment. In this case all you need to keep is the token id, so that you can reload the token and send a signal.

              • 4. Re: subprocess ? or task-node with *blocking* ?
                for Jbpm Novice

                Hi!

                Thanks a lot!
                I was under prejudice that process.waitFor() or process.wait() dosen't work correct on linux.
                So I initially did not think about it. Whatever you said makes perfect sense. I was under impression that hibernation will take care of if i change something in database. huh!