14 Replies Latest reply on Feb 14, 2012 11:03 AM by scurvo

    jBPM5 - How to abort a already running ProcessInstance?

    scurvo

      Hi all,

       

      I wanted to stop/abort a running process but don't know how.

      I create my KnowledgeBase, the StatefulSession, and the WorkItem for the Service Task for the process and I startProcess(...), but how do i stop it before it reaches the end?

       

      I seen the "void abortProcessInstance(long processInstanceId);" function but it doesn't do nothing and the process continues.

       

      Anyone can help ?

        • 1. jBPM5 - How to abort a already running ProcessInstance?
          salaboy21

          Hi there,

          what do you mean by the process continue running?

          if you create a human task inside the task server you need to go and cancel the task as well. The Human tasks runs decoupled from the process itself, so if you abort the process you probably want to abort all the related tasks as well.

          Greetings.

          • 2. jBPM5 - How to abort a already running ProcessInstance?
            scurvo

            What i do is i create a Service Task like this:

             

            ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());

            ProcessInstance pi = ksession.startProcess(....)

             

            And i try to abort the process like this:

             

            ksession.abortProcessInstance(pi.getId());

             

            But it continues to execute the so called Service Task...

            Can show me how to abort this service task also?

            • 3. jBPM5 - How to abort a already running ProcessInstance?
              salaboy21

              Hi there, i don't want to sound harsh but did you read the official documentation?

              http://sourceforge.net/projects/jbpm/files/jBPM%205/jbpm-5.0-CR1/jbpm-5.0-CR1-docs.zip/download

              (this is not on the official webpage, but it will be there soon).

               

              You have a Client to interact with the Human Task Service. In that client you can call the abort method for each task that was created from your processes.

              Greetings.

               

              PS: we usually use the "Human Task" workitemhandler id to bind the ServiceTaskHandler, did you change the name of the service in the BPMN2 file? did you see an exception like this: "org.drools.WorkItemHandlerNotFoundException: Could not find work item handler for Human Task" in your logs?

              • 4. jBPM5 - How to abort a already running ProcessInstance?
                scurvo

                I just followed the example BPMN2-ServiceProcess.bpmn2 to create a process that executes a given java class, and to test that example the following is done:

                KnowledgeBase kbase = createKnowledgeBase("BPMN2-ServiceProcess.bpmn2");

                StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);

                ksession.getWorkItemManager().registerWorkItemHandler("Service Task", new ServiceTaskHandler());

                 

                I assumed this would be the procedure to create a process that executes a given method of a given java class (as shown in the example).

                 

                I will continue reading the doc and try to use the Task Client.

                Thank you so far

                • 5. jBPM5 - How to abort a already running ProcessInstance?
                  krisverlaenen

                  The ServiceTaskHandler is actually executing the service synchronously.  That means that the service will have executed before you'll have the chance to abort the process instance.

                   

                  In general though, when using asynchronous work item handlers, you abort your process instance, the work item handler will be notified that the service call should be aborted.  In the work item handler, you can then specify how to do this (as the abortWorkItem(..) method.

                   

                  Kris

                  1 of 1 people found this helpful
                  • 6. jBPM5 - How to abort a already running ProcessInstance?
                    scurvo

                    So is there a way to abort a ServiceTask? Or make it asynchronous? I'm kinda lost ...

                    If not is there another way of defining a bpmn2 process that executes a given method of a given java class?

                    • 7. jBPM5 - How to abort a already running ProcessInstance?
                      salaboy21

                      You should take a look at work items. With workitems you have that mechanism to call asynchronously or synchronously external systems using java code.

                      Greetings!

                      • 8. jBPM5 - How to abort a already running ProcessInstance?
                        scurvo

                        I'm looking into the example of creating a new work item called "Notification" in the documentation. But it never shows how to define that work item in the process.bpmn2 file through XML. I have to create my own tags and relative xsd definition?

                        • 9. Re: jBPM5 - How to abort a already running ProcessInstance?
                          scurvo

                          I managed to create my Work Item so far so thanks for the help on that tip, it's concept it's just what i was looking for.

                          Only thing now is how to abort the damm Work Item...

                           

                          I try getWorkItemManager().abortWorkItem(WORK_ITEM_ID); but never calls my workItemhandler.abort() method....

                          • 10. jBPM5 - How to abort a already running ProcessInstance?
                            salaboy21

                            No, In the BPMN2 xml you can use the service task for that.. Drag one of the examples in the palete for example the Log Node under Service Tasks and look at the XML. You will notice that WorkItems are binded by name in an attribute.

                            • 11. Re: jBPM5 - How to abort a already running ProcessInstance?
                              scurvo

                              Ok thanks all problem solved.

                               

                              1 - Create a WorkItem with specific execute and abort code;

                              2 - Call the workItem's abort method which defines the specific way to finish that workItem and warns the manager of it's abortion too;

                               

                              I thinks that's it, thanks Mauricio and Kris for the help

                              • 12. Re: jBPM5 - How to abort a already running ProcessInstance?
                                salaboy21

                                No problem, ping us if you need something else!

                                • 13. Re: jBPM5 - How to abort a already running ProcessInstance?
                                  sridhar532

                                  Hi Scurvo,

                                   

                                  Can you share your example of terminating the ProcessInstance. Thanks

                                  • 14. Re: jBPM5 - How to abort a already running ProcessInstance?
                                    scurvo

                                    Hi,

                                     

                                    The way I solved it and according to my problem was:

                                     

                                    1 - Create a Work Item handler and the work item with abort methods:

                                     

                                    public class PrintWorkItemHandler extends MyWorkItemHandler {

                                        public Printer2 p;

                                        protected Date startTime;

                                        protected Date endTime;

                                     

                                        class printThread extends Thread {

                                     

                                     

                                            protected long wiID;

                                     

                                     

                                            public printThread(long wiID) {

                                                this.wiID = wiID;

                                            }

                                     

                                     

                                            public void run() {

                                                startTime = new Date();

                                                p = new Printer2();

                                                p.printAlot("adasd");

                                     

                                     

                                                // notify manager that work item has been completed

                                                mng.completeWorkItem(wiID, null);

                                                endTime = new Date();

                                                System.out.println("PRINT ENDED and took  " +

                                                                JBPMUtil.dateDiff(startTime, endTime));

                                            }

                                        }

                                     

                                     

                                        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

                                            super.addWorkItem(workItem);

                                            super.setWorkItemManager(manager);

                                     

                                     

                                            new printThread(workItem.getId()).start();

                                        }

                                     

                                     

                                        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {

                                            System.out.println("ABORTED");

                                            p.stop = true;

                                            manager.abortWorkItem(workItem.getId());

                                        }

                                    }

                                     

                                    2 - When i want a workItem to finish i do:

                                     

                                    mng.completeWorkItem(wiID, null); to complete ir

                                    or

                                    manager.abortWorkItem(workItem.getId()); to abort it