3 Replies Latest reply on Oct 8, 2009 5:31 PM by Ronald van Kuijk

    How to stop a process instance

    Frantz Degrigny Newbie

      Is it possible to programatically terminate a process instance ?

      I tried the ProcessIntance.end() method but it doesn't work.
      After this method was called the token continue to the next task node and
      the process status in not equal to "terminated".
      The method ProcessInstance.hasEnded() return false.

      Did I misunderstood something ?

      What I need to do is to programatically terminate the current process instance when an unexpected exception occurs.

      Any ideas to do this ?
      Personally, I was very near to give up with all this over-complicated stuff.

        • 1. Re: How to stop a process instance
          Ronald van Kuijk Master

          Do you have a unittest that I can run? You do not demonstrate where you want to end the process instance.

          And what doe you mean by 'over-complicated'? Nothing from your post points to something that is complicated, let alone over-complicated. It might be a bug, yes, but over-complicated it is not.

          • 2. Re: How to stop a process instance
            Frantz Degrigny Newbie

            Last I found how to do this.
            In fact the ProcessIntance.end() method really terminate the process but not all the running process tasks in it (this has confused me).
            The process tasks have to be terminated separately.

            At last, I have made all my ActionHandlers extends a custom base one :

            public abstract class BaseActionHandler implements ActionHandler {
            
             public void execute(ExecutionContext executionContext) throws Exception {
             try {
             doAction(executionContext);
             } catch (Throwable t) {
             handleException(t, executionContext);
             }
             }
            
             public abstract void doAction(ExecutionContext executionContext) throws Exception;
            
             protected void handleException(Throwable t, ExecutionContext executionContext) throws Exception {
             log.fatal("Error in " + this.getClass().getName() + ": " + t.getMessage(), t);
            
             //try to stop process instance and associated tasks
             ProcessInstance processInstance = executionContext.getProcessInstance();
             stopProcess(processInstance);
            
             throw new JbpmException(t.getMessage(), t);
             }
            
             protected void stopProcess(ProcessInstance processInstance) {
             JbpmContext jbpmContext = JbpmConfiguration.getInstance().getCurrentJbpmContext();
             Collection<TaskInstance> taskInstances = unchekedCast(processInstance.getTaskMgmtInstance().getTaskInstances());
             for(TaskInstance task : taskInstances) {
             if( ! task.hasEnded() ) {
             task.setSignalling(false);
             task.cancel();
             jbpmContext.save(task);
             }
             }
             processInstance.end();
             }
            }


            What I have found over-complicated is the JBPM API itself. I'm working with for few month now and there is many things I still cannot understand. For example, the various variables scopes are very confusing and the semantic of many operations are not very clear.
            My customers have very basics needs for their workflows but I have discover that they cannot be done simply with the JBPM API.


            • 3. Re: How to stop a process instance
              Ronald van Kuijk Master

              The api in three was kind of blurry, yes, that is why it was simplified in 4. (But asking is always possible)

              various variable scopes? Task local, transient and normal.

              If the semantics of the various operations are not clear after working with it for several months I think something else might be wrong.

              And a statement like

              My customers have very basics needs for their workflows but I have discover that they cannot be done simply with the JBPM API.

              Is like saying there are no obstacles between the earth and the moon, so it should be simple to get there but I do not know how.

              What I mean by this is that the problem in reality is not that simple or you lack the knowledge (no offence) to see it. Complex processes can be done with jBPM, see slide 15 of http://www.slideshare.net/tombaeyens/jbpm-community-day-full-scale-stp-with-jbpm.

              Tasks not being ended when a process is ended can be changed by setting the end-complete-process attribute on the end state to true.