1 2 Previous Next 17 Replies Latest reply on Aug 26, 2008 2:50 AM by lblaauw

    Terminated or deleted process instance?

    coolex

      Hello!

      I am working on a small application and use JBPM on my normal JBoss server without the jbpm-console.
      I can start my processes, navigate through the processes and end them.
      When I end my process instances they simply disappears but I don't really know if the process instance still exists in the JBPM DB.

      So, what happens with an ended process instance? Is still available and able to be restarted again?

      bye

        • 1. Re: Terminated or deleted process instance?
          kukeltje

           

          So, what happens with an ended process instance?

          It stops running

          Is still available

          There is something in the database yes

          and able to be restarted again?

          Depends... you can make the end date of the process null, then it is 'running' again, but the node it is in will still be the end node...

          • 2. Re: Terminated or deleted process instance?
            coolex

            Aha, ok.
            So, the process instance is not deleted after it has been terminated?
            Can I restart it, if I know its ID?

            • 3. Re: Terminated or deleted process instance?
              kukeltje

              look at my last remarks about 'restarting' and yes you need something like the id. Restarting from the beginning is *not* automatically done, unless you e.g. move the root token to the start node, but behaviour would probably be strange in some cases since there are already process variables with values

              • 4. Re: Terminated or deleted process instance?
                twiceknightly

                related to this topic I have been thinking about how to totally get rid of a process instance from a db. Obviously there will be a lot of stuff hanging around. If I were to perform a hibernate delete on the process instance would it cascade and delete everything associated with the process instance?

                • 5. Re: Terminated or deleted process instance?
                  kukeltje

                  yes it will cascade

                  • 6. Re: Terminated or deleted process instance?
                    lblaauw

                    Hey,

                    I just wrote a handler to get rid of all the process instance data including the cascades. The actual delete is kinda tricky in a sense that since all collections and object properties are lazily initialized it requieres you to load them up in a custom command object to get the actual data, then run through them, clear them and only then will a delete on process instance throught the jbpmContext work correctly with all cascades.

                    Greetz,
                    Leo


                    "twiceknightly" wrote:
                    related to this topic I have been thinking about how to totally get rid of a process instance from a db. Obviously there will be a lot of stuff hanging around. If I were to perform a hibernate delete on the process instance would it cascade and delete everything associated with the process instance?


                    • 7. Re: Terminated or deleted process instance?
                      mputz

                       

                      The actual delete is kinda tricky...


                      Why not simply use
                      org.jbpm.db.GraphSession#deleteProcessInstance(long processInstanceId)
                      ?

                      • 8. Re: Terminated or deleted process instance?
                        lblaauw

                        That wont work since you will have a non complete processinstance at your hands caused by all lazy loading on the process instance...

                        Regards,
                        Leo

                        "mputz" wrote:
                        The actual delete is kinda tricky...


                        Why not simply use
                        org.jbpm.db.GraphSession#deleteProcessInstance(long processInstanceId)
                        ?


                        • 9. Re: Terminated or deleted process instance?
                          twiceknightly

                           

                          "lblaauw" wrote:
                          Hey,

                          I just wrote a handler to get rid of all the process instance data including the cascades.


                          Care to share what you did? I'm sure a fair few people would appreciate it. It seems an big ommission if the one "out of the box" doesn't clean up properly

                          • 10. Re: Terminated or deleted process instance?
                            mputz

                            Leo, the GraphSession.deleteProcessInstance method *should* handle all references correctly, and should thus get rid of all data related to a process instance. If it does not, it would be great if you could provide more info about what is missed out, so that this can be fixed.

                            • 11. Re: Terminated or deleted process instance?
                              lblaauw

                              Sure,

                              I dont claim this to be perfect but hey it works, so here is the code for the handler:

                              public class VerwijderProcessInstanceHandler extends JbpmHandlerProxy{
                               private static final long serialVersionUID = -6125309218094541298L;
                               /** Logger available to subclasses */
                               protected final Log logger = LogFactory.getLog(getClass());
                              
                               @SuppressWarnings("unchecked")
                               @Override
                               public void execute(ExecutionContext executionContext) throws Exception {
                               try {
                               logger.debug("executing VerwijderProcessInstanceHandler...");
                               ProcessInstance pi = executionContext.getProcessInstance();
                               logger.debug("ProcessInstance is null? " + (pi==null));
                               List<Token> allTokens = pi.findAllTokens();
                               logger.debug("allTokens of processInstance: " + allTokens.size());
                              
                               //clear taskinstances from comments
                               Collection<TaskInstance> taskInstances = pi.getTaskMgmtInstance().getTaskInstances();
                               for(TaskInstance ti : taskInstances){
                               ti.getComments().clear();
                               executionContext.getJbpmContext().save(ti);
                               }
                              
                               //clear tokens from comments..
                               if(allTokens.size() > 0){
                               for(Token t : allTokens){
                               //get all comments per token...
                               if(!t.getComments().isEmpty()){
                               logger.debug("cleared comments before deleting? " + t.getComments().isEmpty());
                              
                               for(Object o : t.getComments()){
                               Comment c = (Comment)o;
                               c.setTaskInstance(null);
                               }
                              
                               //clearing comments on taskinsantce manually... pfff
                               t.getComments().clear();
                               }
                              
                               executionContext.getJbpmContext().save(t);
                               logger.debug("t.getComments().size(): " + t.getComments().size());
                               }
                               }
                              
                               //saving without comments and taskinstances within comments...
                               executionContext.getJbpmContext().save(pi);
                              
                               executionContext.getJbpmContext().getGraphSession().deleteProcessInstance(pi, true, true);
                               } catch (Exception e){
                               //Exception upon deleting processinstance..
                               e.printStackTrace();
                               logger.error(e.getMessage());
                               }
                               }
                              }
                              


                              Basically I have this handler configured in a Spring application context and then use the spring-jbpm integrationproxy. So I call this handler from within my jBPM process on the action like so:

                               <end-state name="end-bevestigRelatieVerzoek">
                               <event type="node-enter">
                               <action name="verwijderProcessInstanceAction" class='org.springmodules.workflow.jbpm31.JbpmHandlerProxy' config-type="bean">
                               <targetBean>VerwijderProcessInstanceHandler</targetBean>
                               </action>
                               </event>
                               </end-state>
                              


                              Allthough I strongly agree with you that I expect the jBPM (engine) to cleant up all process data after a processinstance finishes and I consider it to be a bug that it doesnt ! Coming from working for years with commercial workflow engine products the default behaviour I have allways encountered is to purge all data from the BPM database upon completion. This ensures a lean and mean processing database necesary for speedy processing with large numbers of processinstances or cases. If you then need historical data you as a developer store that in a seperate database....

                              But maybe some of the core jBPM folks in here could comment on this ?

                              Greetings and now off to my weekend,

                              Leo

                              "twiceknightly" wrote:
                              "lblaauw" wrote:
                              Hey,

                              I just wrote a handler to get rid of all the process instance data including the cascades.


                              Care to share what you did? I'm sure a fair few people would appreciate it. It seems an big ommission if the one "out of the box" doesn't clean up properly


                              • 12. Re: Terminated or deleted process instance?
                                lblaauw

                                hey,

                                Well as you can see from my handler code above that is the only way I could get GraphSession.deleteProcessInstance to delete the ProcessInstance and to have the cascades work correctly. The case i have is that Comment objects are attached to tokens in the process instance. Basically I had to clean out all references to the Comments everwhere manually as you can see from my code. Without this 'cleanup' code I get exceptions back from hibernate basically telling me there are references on Comment instances left so the delete fails.

                                Regards,
                                Leo


                                "mputz" wrote:
                                Leo, the GraphSession.deleteProcessInstance method *should* handle all references correctly, and should thus get rid of all data related to a process instance. If it does not, it would be great if you could provide more info about what is missed out, so that this can be fixed.


                                • 13. Re: Terminated or deleted process instance?
                                  mputz

                                   

                                  The case i have is that Comment objects are attached to tokens in the process instance.


                                  I just tested GraphSession.deleteProcessInstance on a process with related comments, and they were deleted just fine. This was with jBPM 3.2.3.

                                  • 14. Re: Terminated or deleted process instance?
                                    kukeltje

                                    Same here. Works as expected

                                    1 2 Previous Next