4 Replies Latest reply on Feb 3, 2006 4:19 PM by Adrian Andrei

    BPEL Process Instance

    Adrian Andrei Newbie

      I am interested in capturing a BPEL process execution, such that the ATM example. I can see that MessageSession spans between the receive and the reply acitivities, but I would like to know when the BPEL process ends.

      Is there a mechanism that one can use programatically to capture the start and end events of a BPEL process?

      I added my own code in MessageSession.java, but this only works for simple examples, such that Hello, where the BPEL process instance ends together with the reply activity.

      Regards
      AA

        • 1. Re: BPEL Process Instance
          Alejandro Guizar Master

          Yes, there is. If you take a look at the console logs, you will notice the events of the underlying jBPM graph. Right now there is no declarative way to capture them, but you can do it programatically.

          After you deploy the process archive, but before you deploy the web services, load the process definition, perform the following operations, and save it back.

          // register the action we want executed at the end
           Action endAction = new Action();
           endAction.setName("endAction");
           processDefinition.addAction(endAction);
           // delegate the action's execution to a handler
           Delegation endDelegation = new Delegation();
           endDelegation.setClassName(EndHandler.class.getName());
           endAction.setActionDelegation(endDelegation);
          
           // register an event of type process end
           Event event = new Event(Event.EVENTTYPE_PROCESS_END);
           processDefinition.addEvent(event);
           // associate the above action with the event
           event.addAction(endAction);

          As a reference, the EndHandler is:
          public class EndHandler implements ActionHandler {
          
           private static final long serialVersionUID = 1L;
          
           public void execute(ExecutionContext exeContext) throws Exception {
           [...]
           }
           }


          • 2. Re: BPEL Process Instance
            Adrian Andrei Newbie

            Thanks for your response, nice.

            Just a note, the start process event is never triggered. So I changed BpelDefinition class, startProcessInstance to have that triggered:

            public void startProcessInstance( ProcessInstance processInstance,
             Receiver trigger )
             {
             Token scopeToken = processInstance.getRootToken();
             ScopeInstance scopeInstance = ScopeInstance.get( scopeToken );
             ExecutionContext context = new ExecutionContext( scopeInstance.getNormalFlowToken() );
            
             try
             {
             scopeInstance.enableEvents();
             // new line
             fireEvent( Event.EVENTTYPE_PROCESS_START,
             context );
            
             new ProcessInstanceStarter( context, trigger ).visit( this );
             }
             catch ( Throwable t )
             {
             scopeInstance.getDefinition().raiseException( t,
             context );
             }
             }
            


            Thanks
            AA


            • 3. Re: BPEL Process Instance
              Alejandro Guizar Master

              Big oops. I thought the ProcessInstance fired it upon its construction:

              // fire the process start event
               if (rootToken.getNode()!=null) {
               ExecutionContext executionContext = new ExecutionContext(rootToken);
              processDefinition.fireEvent(Event.EVENTTYPE_PROCESS_START, executionContext);
               }

              At this point the root token will point to the start node if there is one. However, BPEL processes do not have a start node, as they could potentially have multiple start activities (i.e. < receive>s with createInstance="yes").

              Thanks for reporting the problem. I'll just fire the event in BpelDefinition.createProcessInstance() rather than .startProcessInstance() to be more consistent with the jBPM behavior. Could you open a JIRA issue for tracking purposes?

              • 4. Re: BPEL Process Instance
                Adrian Andrei Newbie

                Done. See issue BPEL-89