9 Replies Latest reply on Jul 10, 2009 7:40 AM by nazartm

    Saving long spanning process in jBPM 4.0

    nazartm

      Hi all,

      In jBPM 3.0 we could save the state of the process to the database and later access it later. I was wondering how to do this with jBPM 4.0 since, jbpmcontext is not in the api.

      For those who want to know what exactly I'm doing, I have an asynchronous web-service that uses callback method. After a state initiates the web-service, I want to save the state and only when the callback method is called, I want to proceed further.

      Any suggestions and comments are welcome :)

        • 1. Re: Saving long spanning process in jBPM 4.0
          kukeltje

          Uhhmmmm first suggestion would be to read some docs, look at some examples, blogs etc...

          • 2. Re: Saving long spanning process in jBPM 4.0
            nazartm

            Let me try to explain myself better. I did read the User guide for version 4.0, the developer guide had some outdated API but i've read that as well.

            Let's say, when i reach a certain node, I call an asynchronous job. When this job is complete, it will call a callback method, say callbackAtoB(). From within this callback method, I need to signal so that execution can proceed to the next state.

            I attempted to solve it using an eventListener A which is triggered when state A is entered. For simplicity's sake, I keep the processEngine in a static field. I instantiate the process. Now when callbackAtoB() is called, I use the executionId given in the eventListener in an attempt to singal. However, I get that org.jbpm.api.JbpmException: execution Process.1 does not exist.

            So I was wondering if there is another way of doing it, or is there a simple thing i missing.

            thanx in advance :)

            • 3. Re: Saving long spanning process in jBPM 4.0
              kukeltje

              I think you are missing some simple thing, but from just reading text I'm not going to guess etc. Can you make a simple unit test that demonstrates what you try to achieve. This should be possible from what I read (the async stuff can be emulated I think within the unit test)

              • 4. Re: Saving long spanning process in jBPM 4.0
                nazartm

                Let's say this is the workflow:
                [img]http://img198.imageshack.us/img198/9325/screenshotukr.png[/img]

                <process name="phoneCheckProcess" key="PCP" xmlns="http://jbpm.org/4.0/jpdl">
                 <start g="72,187,48,48" name="start">
                 <transition to="phoneCheck"/>
                 </start>
                
                 <state continue="async" g="211,178,92,52" name="phoneCheck">
                 <on event="start">
                 <event-listener class="eventListener.MyEventListener"/>
                 </on>
                 <transition to="proceed"/>
                 </state>
                 <state g="390,181,92,52" name="proceed">
                 <transition to="end"/>
                 </state>
                <end g="601,186,48,48" name="end" state="finished"/>
                </process>


                When execution reaches MyEventListener, I call a web-service that is asynchronous (for testing purposes i use a mock). When that function completes, it calls a callbackHandler.

                I have a class that keeps a static processEngine so that I can access it from my test case and callback handler.

                In my test case;
                ProcessInstance processInstance = MyController.getInstance().getExecutionService().startProcessInstanceByKey("PCP");
                 Execution executionInQuery = processInstance.findActiveExecutionIn("phoneCheck");
                 assertNotNull("Supposed to be <phoneCheck>", executionInQuery);


                Here, things go like this. The web-service is called, and it calls the calbackHandler. The callback handler, accesses the static Process engine and does the following:
                ProcessInstance instance = getInstance().getExecutionService().signalExecutionById(executionId);

                where execution id is retrieved from the eventListener.

                Now this gives me the exception that the executionId does not exist. I cannot figure this out. I have been trying various things here, but it still doesn't work. Any help or ideas would be greatly appreciated.

                • 5. Re: Saving long spanning process in jBPM 4.0
                  nazartm

                  Extra info, if i try to signal using the same execution ID from within junit test case, it works. But then, my purpose is lost.

                  • 6. Re: Saving long spanning process in jBPM 4.0
                    kukeltje

                    I'm surprised it works in your unit test and not with a webservice. You most likely do two different things then. From the words and some of your code I still see/read nothing that makes it impossible. Probably something to do with transaction demarcation so in the unittest case the instance is save to the database and in the other it isn't.

                    • 7. Re: Saving long spanning process in jBPM 4.0
                      nazartm

                      Yea, I also suspect transaction problems, will try using JTA transaction on JNDI binded Process Engine.

                      • 8. Re: Saving long spanning process in jBPM 4.0

                        try to reload the execution instance before you signal it.

                        ProcessInstance execution = executionService.findProcessInstanceById(executionId);
                        execution.signalExecutionById(executionId);
                        




                        • 9. Re: Saving long spanning process in jBPM 4.0
                          nazartm

                          I did try reloading the execution, but it didn't help. It has something to do with transactions I figure.

                          I attempted doing the whole thing using JNDI with a web applications. That works wonderfully. So it is the testing environment that I can't quite figure out. We will see.

                          Thanks guys for all your input :)