Given:
<process id="executionListener"> <extensionElements> <camunda:executionListener class="MyExecutionListener" event="end" /> </extensionElements> <startEvent id="theStart" /> <sequenceFlow sourceRef="theStart" targetRef="scriptTask" /> <scriptTask id="scriptTask" scriptFormat="groovy"> <extensionElements> <camunda:executionListener class="MyExecutionListener" event="end" /> </extensionElements> <script><![CDATA[throw new org.camunda.bpm.engine.delegate.BpmnError("123");]]></script> </scriptTask> <sequenceFlow sourceRef="scriptTask" targetRef="theEnd" /> <endEvent id="theEnd" /> </process>
public MyExecutionListener implements ExecutionListener { public void notify(DelegateExecution execution) throws Exception { System.out.println("event type: " + execution.getEventName()); System.out.println("current activity: " + execution.getCurrentActivityId()); } }
When:
start an instance of the process
Then:
The provided execution listener MyExecutionListener is invoked twice:
1) the script task is ended, the following is logged out:
- event type: end
- event type: scriptTask
2) the process is ended, the following is logged out: - event type: end
- event type: scriptTask
Problem:
In both cases the DelegateExecution#getCurrrentActivityId() returns scriptTask, so that it is not possible to determine whether the 'end' is for the overall process instance/execution or for the individual activity which was cancelled/ended.
Possible Solutions:
- We expose the CoreExecution#getEventSource() which sets always the correct activity for which the execution listener is invoked (and in case of the process it returns the process definition). But be aware, that instead exposing simple the method we can only expose the id of the event source. As a consequence, inside the listener the method Delegate#getEventSourceId() must be used.
- We fix that DelegateExecution#getCurrentActivityId() returns not scriptTask in case it is notified for the 'end' for the overall process instance/execution
Hint:
This is especially a problem, if you provide an execution listener via a process application (ie. ProcessApplicationInterface#getExecutionListener().
This is the controller panel for Smart Panels app
- is related to
-
CAM-5552 Global process application event execution listener is not invoked on start and end of a process instance
- Closed