1 2 Previous Next 24 Replies Latest reply on Sep 9, 2014 3:07 AM by mayankjain

    How to make a process instance go on with jBPM5?

    cheney-dut

      Hi all ,

      The Code:

      KnowledgeBase kbase = readKnowledgeBase("demo.bpmn");

      StatefulKnowledgeSession ksession = createKnowledgeSession(kbase, 1); // JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, config, env);

       

      ProcessInstance processInstance = ksession.getProcessInstance(1); // i get the trucial process instance

       

      But what can i do to make the process instance go on?

      Anyone can help?

      Thanks!

        • 1. How to make a process instance go on with jBPM5?
          eaa

          In jBPM5, when you start a process, it executes all the nodes it can. If you don't have any wait-state, then the process will be completed when the session.startProcess() method returns.

          There are 3 ways (somebody please correct me if I'm forgeting someone) to define wait-points:

          1. Asyncronous WorkItemHandlers in your Service Task Nodes:
            When you define a Service Task in your process, you need to assign a handler for it. This handler could be synchronous or asynchronous. It will be synchronous only if you invoque workItemManager.completeWorkItem() inside handler's executeWorkItem() method. The only difference with asynchnornous handlers is that they don't complete the work item inside. They delegate this behaviour to an external mechanism.
            When the process finds a Service Task Node, its executes the associated handler. If the handler conpletes the work item, the execution continues. If the handler doesn't complete the work item, the process reaches a wait-state (if there are no more parallel paths to continue with). When the process reaches a wait-state, it state is persisted (if you are using persistence, of course ).
            Asynchronous work item handlers are good for (time) expensive calls to external systems. If you don't know how long the external sytem will take to respond, then you could use an asynchronous work item handler. The process will call the external system, everythng is going to be persisted and you can even dispose you ksession and stop the Thread that performed the startProcess() call. You still need to have a mechanism for continue the execution of the process when the external system ends. You will need at least the id of the ksession and the id of the work item to be able to restore you ksession ( JPAKnowledgeService.loadStatefulKnowledgeSession() ) and to complete the work item ( ksession.getWorkItemManager().completeWorkItem()). The completeWorkItem() method wil execute as many nodes as it can until it reaches a new wait-point or until the process finishes.
          2. Human Task Nodes: Human tasks are handled like asynchronous Work Items by jBPM5. jBPM5 already comes with a WorkItemHandler implementation for Human Tasks: WSHumanTaskHandler. This handler will communicate with a Task Service (also provided by jBPM5) and create a new Task in it. Then, it will wait for someone (using Human Client API) to complete/cancel the task.
          3. External Events: You can define external events handlers in your process using an intermediateCatchEvent. Then, from outside your process you can signal the event using ksession.signalEvent() method. If you combine a intermediateCatchEvent with a converging parallel gateway, you get a wait-state.

           

          I have a set of simple tests that show some of the things I have mentioned here. You can download and try them from here:

          https://github.com/esteban-aliverti/JBPM-Samples

           

          Best Regards,

          • 2. How to make a process instance go on with jBPM5?
            salaboy21

            That's right!

            Check out the examples located here too: https://github.com/Salaboy/Drools_jBPM5-Training-Examples

            Please give us feedback about them if you find them useful

            • 3. How to make a process instance go on with jBPM5?
              cheney-dut

              Thanks for your reply!

              Right now, i take the first methord. And by the way, i have to know the workItem ID, isn't it? But how to know?

              i readed some examples, including your supply! i find that WorkItemManager.completeWorkItem() is used in the same testCase. In another testCase, how to get the workItem, or how to complete the workdItem?

               

              WIth the second method, it takes C/S mode. When the jbpm is self-governed, it is userful, isn't it? But at this time, how to manage the transaction?

              Looking forward to your reply!

              Thanks!

              • 4. How to make a process instance go on with jBPM5?
                cheney-dut

                Thanks! These exampls are useful. But the process is ended in one testCase.

                Now the scene is that i generate one process instance in a testCase and i want to make it go on in another.

                How?

                Have any suggestion!?

                Thank you!

                • 5. How to make a process instance go on with jBPM5?
                  eaa

                  Remember that you will need to make an external mechanism to hanlde the result of async calls. Inside the WorkItemHandler you can get the workItem Id. Two (of the probably infinite) options that you have are:

                  1. Pass the id (along with the session Id) to the external system. The external system, when finishes, can use those values to perform a call to your system and complete the work item.
                  2. Create a complete isolated mechanism for handling async calls to external systems. In this scenario, you could call the external system on your WorkItem Handler and then notify this third system (the isolated system I have mentioned before) that a new "task" is running. When the external system completes its work, it notifies this to the same third system. When a task is completed, the third system will notify your system about it.

                   

                  Best Regards,

                  • 6. How to make a process instance go on with jBPM5?
                    eaa

                    If you want to start a process in one test and complete it in another, you will need to follow these steps:

                    • Your process must have a wait-state. If it doesn't the process will start and end in the startProcess() call.
                    • You need to enable persistence. When the process reaches the wait-state in the first test it will be persisted in the DB.
                    • The second test needs to know the session id generated in the first test. You can get this id from the session object created in the first test. You wil need to store it in a place reachable by the second test. If you want to keep it simple, just use a static variable.
                    • Whithin the first test, your process will eventually execute the Handler you have configured for your Work Item. This handler will need to store the workItem id somewhere (again, in a place reachable by test number 2)
                    • In the second test, using the session id stored in th efirst test, you need to retrieve the session from the database. The best way to do this is using JPAKnowledgeService.
                    • Once you have the session, you need to call session.getWorkItemManager().completeWorkItem() using the work item id previously saved. 

                     

                    Best Regards,

                    • 7. How to make a process instance go on with jBPM5?
                      cheney-dut

                      Taking your advise, i store the session id and the work item id and can complete a process instance which has only one Huam Task. When my process has one more and the process instance reached the second Huam Task node, i can get an exception:

                      2011-04-18 10:59:17,773 ERROR [org.drools.persistence.SingleSessionCommandService] - Could not commit session

                      org.drools.WorkItemHandlerNotFoundException: Could not find work item handler for Human Task

                          at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.throwWorkItemNotFoundException(JPAWorkItemManager.java:60)

                          at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.internalExecuteWorkItem(JPAWorkItemManager.java:55)

                          at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:102)

                          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

                          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:186)

                          at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)

                          at org.jbpm.workflow.instance.impl.ExtendedNodeInstanceImpl.triggerCompleted(ExtendedNodeInstanceImpl.java:47)

                          at org.jbpm.workflow.instance.node.StateBasedNodeInstance.triggerCompleted(StateBasedNodeInstance.java:162)

                          at org.jbpm.workflow.instance.node.StateBasedNodeInstance.triggerCompleted(StateBasedNodeInstance.java:143)

                          at org.jbpm.workflow.instance.node.WorkItemNodeInstance.triggerCompleted(WorkItemNodeInstance.java:206)

                          at org.jbpm.workflow.instance.node.HumanTaskNodeInstance.triggerCompleted(HumanTaskNodeInstance.java:90)

                          at org.jbpm.workflow.instance.node.WorkItemNodeInstance.workItemCompleted(WorkItemNodeInstance.java:268)

                          at org.jbpm.workflow.instance.node.WorkItemNodeInstance.signalEvent(WorkItemNodeInstance.java:244)

                          at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.signalEvent(WorkflowProcessInstanceImpl.java:333)

                          at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.completeWorkItem(JPAWorkItemManager.java:119)

                          at org.drools.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:69)

                          at org.drools.command.runtime.process.CompleteWorkItemCommand.execute(CompleteWorkItemCommand.java:32)

                          at org.drools.persistence.SingleSessionCommandService.execute(SingleSessionCommandService.java:295)

                          at org.drools.command.impl.CommandBasedStatefulKnowledgeSession$1.completeWorkItem(CommandBasedStatefulKnowledgeSession.java:146)

                          at jbpm.demo.bpm.process.PersistenceTest.testProcessGoOn(PersistenceTest.java:144)

                          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                          at java.lang.reflect.Method.invoke(Method.java:597)

                          at junit.framework.TestCase.runTest(TestCase.java:154)

                          at junit.framework.TestCase.runBare(TestCase.java:127)

                          at junit.framework.TestResult$1.protect(TestResult.java:106)

                          at junit.framework.TestResult.runProtected(TestResult.java:124)

                          at junit.framework.TestResult.run(TestResult.java:109)

                          at junit.framework.TestCase.run(TestCase.java:118)

                          at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)

                          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

                          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

                          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

                          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

                          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

                       

                      What's the matter? How to deal?

                      Thanks!

                      • 8. How to make a process instance go on with jBPM5?
                        eaa

                        Ups... I forgot to tell you something . Work Item Handlers bindings are not persisted. So each time you restore your session, you need to configure the handlers again using ksession.getWorkItemManager().registerWorkItemHandler(id, handler);

                        • 9. How to make a process instance go on with jBPM5?
                          cheney-dut

                          That is very good. Thank you!

                          But i have another question that i can't find the end information of the process instance ended, such as the end_date field in processinstancelog table which is null.

                          Why? Or what i have to do?

                          Looking forward to your reply!

                          • 10. How to make a process instance go on with jBPM5?
                            eaa

                            When a process instence ends, its information is deleted from the data base. AFAIK, you will need to use jbpm-bam to get execution history.

                             

                            Best Regards,

                            • 11. How to make a process instance go on with jBPM5?
                              cheney-dut

                              It's my mistake. i start process with jbpm-bam, but do not use it when make then process instance go on.

                              Hhe! Thank you!

                              • 12. Re: How to make a process instance go on with jBPM5?
                                mariemm

                                Hi,

                                 

                                it is really necessary (or recommended) to remember sessionId when starting process in one test and finishing in another?

                                It works also when you create always new session.

                                • 13. Re: How to make a process instance go on with jBPM5?
                                  mscetin

                                  Hi,

                                   

                                  I restore a session using JPAKnowledgeService.loadStatefulKnowledgeSession (copy/paste from org.jbpm.integration.console.CommandDelegate which looks like a workaround) and re-registering work item handlers using WorkItemManager.registerWorkItemHandler method. What I notice is; these handlers are invoked for any newly created process instance but they are not invoked for process instances created before re-storing the session. (Human Task handler - CommandBasedWSHumanTaskHandler works with no problem though). Do I need to do anything extra to associate existing process instances with the handlers?

                                   

                                  I am testing this scenario by deploying a web application that uses jBPM to Glassfish, enabling persistence and stopping and starting the application server in between.

                                  • 14. Re: How to make a process instance go on with jBPM5?
                                    dondragon2

                                    Hi,

                                     

                                    I want to implement the same wait-state but without using the database. I need everything to be in memory.

                                    Currently, I have the following definition in the XML

                                     

                                    <intermediateCatchEvent id="_5" name="_5" >

                                                   <timerEventDefinition>

                                                          <timeDuration>60s</timeDuration>

                                                   </timerEventDefinition>

                                       </intermediateCatchEvent>

                                     

                                    What I want to achieve is that the process waits for x minutes until some external event to complete the subsequent activities or end the process instance if the time elapses. How can i achieve this without JPA?

                                    1 2 Previous Next