4 Replies Latest reply on Oct 15, 2005 8:29 PM by Brian Bulthuis

    Persisting ProcessInstance at arbitrary state

    Brian Bulthuis Newbie

      Hi, I am new to jBPM and it looks great to me so far. There's something I'm not quite getting though - maybe I just don't understand the proper way to use a process definition.

      I want to persist a ProcessInstance at an arbitrary stage of the process execution. For example, a process has three nodes: "Start" "Dostuff" and "End". If I start a new jbpmSession transaction, get the process definition from the database, and signal a new ProcessInstance to start, how do I persist the ProcessInstance somewhere in the "Dostuff" state? I don't think I can make a new jbpmsession/transaction inside another one.

      I've tried manually threading the process execution, but running a process in multiple threads doesn't seem to work well and other topics in this forum indicate that it's not the right way to do things.

      Any pointers would be appreciated. Thanks!

      Brian

        • 1. Re: Persisting ProcessInstance at arbitrary state
          Koen Aers Master

          Brian,

          The ProcessInstance *is* persisted in the "DoStuff" state. The state is the situation in which the process instance is waiting for the next thing to happen.

          Regards,
          Koen

          • 2. Re: Persisting ProcessInstance at arbitrary state
            Brian Bulthuis Newbie

            Thanks, Koen.

            So if I understand correctly, it would not be appropriate to do

            public class MyActionHandler implements ActionHandler {
            
             public void execute(ExecutionContext executionContext) throws Exception {
             saveProcessInstanceToDB();
             String result = someLongRunningPotentiallyUnstableProcess();
             executionContext.getToken.signal(result);
             }
            }


            but instead one should do


            public class MyActionHandler implements ActionHandler {
            
             public void execute(ExecutionContext executionContext) throws Exception {
             long tokenId = executionContext.getToken().getId();
             sendAsyncMessageToStartALongRunningProcess(tokenId);
             }
            }
            
            public class MyMessageConsumer {
            
             public void consumeMessage(tokenId) {
             String result = someLongRunningProcess();
             jbpmSession.beginTransaction();
             Token myToken = jbpmSession.getGraphSession.loadToken(tokenId);
             myToken.signal(result);
             jbpmSession.commitTransactionAndClose();
             }
            }


            or something along those lines?

            Thanks much for your help with my perhaps elementary question.

            Brian.

            • 3. Re: Persisting ProcessInstance at arbitrary state
              Ronald van Kuijk Master

              Yep... and you know what.... look at the latest code in cvs. Work is comming along nice on this part. Maybe you can try it out and find bugs in it.

              Ronald

              • 4. Re: Persisting ProcessInstance at arbitrary state
                Brian Bulthuis Newbie

                Great, thanks. I'm putting together a report on jBPM for my dev team - it looks promising. If we decide to go with jBPM you'll be hearing a lot more from me and I'll try to help out where I can - reporting bugs or whatever!

                Thanks for your hard work on this promising project and for the prompt replies in the forum.

                Brian