Search in sources :

Example 1 with ExecutionListener

use of org.camunda.bpm.engine.delegate.ExecutionListener in project camunda-bpm-platform by camunda.

the class ClassDelegateExecutionListener method notify.

// Execution listener
public void notify(DelegateExecution execution) throws Exception {
    ExecutionListener executionListenerInstance = getExecutionListenerInstance();
    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new ExecutionListenerInvocation(executionListenerInstance, execution));
}
Also used : ExecutionListenerInvocation(org.camunda.bpm.engine.impl.bpmn.delegate.ExecutionListenerInvocation) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener)

Example 2 with ExecutionListener

use of org.camunda.bpm.engine.delegate.ExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListener.

@Deployment
public void testExecutionListener() {
    final AtomicInteger eventCount = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            // this process application returns an execution listener
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    eventCount.incrementAndGet();
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // start process instance
    runtimeService.startProcessInstanceByKey("startToEnd");
    // 7 events received
    assertEquals(7, eventCount.get());
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 3 with ExecutionListener

use of org.camunda.bpm.engine.delegate.ExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListenerWithMultiInstanceBody.

@Deployment
public void testExecutionListenerWithMultiInstanceBody() {
    final AtomicInteger eventCountForMultiInstanceBody = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    if ("miTasks#multiInstanceBody".equals(execution.getCurrentActivityId()) && (ExecutionListener.EVENTNAME_START.equals(execution.getEventName()) || ExecutionListener.EVENTNAME_END.equals(execution.getEventName()))) {
                        eventCountForMultiInstanceBody.incrementAndGet();
                    }
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // complete task
    List<Task> miTasks = taskService.createTaskQuery().list();
    for (Task task : miTasks) {
        taskService.complete(task.getId());
    }
    // 2 events are expected: one for mi body start; one for mi body end
    assertEquals(2, eventCountForMultiInstanceBody.get());
}
Also used : DelegateTask(org.camunda.bpm.engine.delegate.DelegateTask) Task(org.camunda.bpm.engine.task.Task) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with ExecutionListener

use of org.camunda.bpm.engine.delegate.ExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testIntermediateSignalEvent.

@Deployment
public void testIntermediateSignalEvent() {
    // given
    final List<String> timerEvents = new ArrayList<String>();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution delegateExecution) {
                    String currentActivityId = delegateExecution.getCurrentActivityId();
                    String eventName = delegateExecution.getEventName();
                    if ("signal".equals(currentActivityId) && (ExecutionListener.EVENTNAME_START.equals(eventName) || ExecutionListener.EVENTNAME_END.equals(eventName))) {
                        timerEvents.add(delegateExecution.getEventName());
                    }
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // when
    runtimeService.startProcessInstanceByKey("process");
    runtimeService.signalEventReceived("abort");
    // then
    assertEquals(2, timerEvents.size());
    // "start" event listener
    assertEquals(ExecutionListener.EVENTNAME_START, timerEvents.get(0));
    // "end" event listener
    assertEquals(ExecutionListener.EVENTNAME_END, timerEvents.get(1));
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) ArrayList(java.util.ArrayList) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with ExecutionListener

use of org.camunda.bpm.engine.delegate.ExecutionListener in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testIntermediateTimerEvent.

@Deployment
public void testIntermediateTimerEvent() {
    // given
    final List<String> timerEvents = new ArrayList<String>();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution delegateExecution) {
                    String currentActivityId = delegateExecution.getCurrentActivityId();
                    String eventName = delegateExecution.getEventName();
                    if ("timer".equals(currentActivityId) && (ExecutionListener.EVENTNAME_START.equals(eventName) || ExecutionListener.EVENTNAME_END.equals(eventName))) {
                        timerEvents.add(delegateExecution.getEventName());
                    }
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // when
    runtimeService.startProcessInstanceByKey("process");
    String jobId = managementService.createJobQuery().singleResult().getId();
    managementService.executeJob(jobId);
    // then
    assertEquals(2, timerEvents.size());
    // "start" event listener
    assertEquals(ExecutionListener.EVENTNAME_START, timerEvents.get(0));
    // "end" event listener
    assertEquals(ExecutionListener.EVENTNAME_END, timerEvents.get(1));
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) ArrayList(java.util.ArrayList) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ExecutionListener (org.camunda.bpm.engine.delegate.ExecutionListener)13 EmbeddedProcessApplication (org.camunda.bpm.application.impl.EmbeddedProcessApplication)9 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 DelegateTask (org.camunda.bpm.engine.delegate.DelegateTask)3 Task (org.camunda.bpm.engine.task.Task)3 ArrayList (java.util.ArrayList)2 ExecutionListenerInvocation (org.camunda.bpm.engine.impl.bpmn.delegate.ExecutionListenerInvocation)2 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)2 ProcessApplicationInterface (org.camunda.bpm.application.ProcessApplicationInterface)1 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)1 ProcessApplicationUnavailableException (org.camunda.bpm.application.ProcessApplicationUnavailableException)1 BpmnParseException (org.camunda.bpm.engine.BpmnParseException)1 JavaDelegate (org.camunda.bpm.engine.delegate.JavaDelegate)1 JavaDelegateInvocation (org.camunda.bpm.engine.impl.bpmn.delegate.JavaDelegateInvocation)1 ClassDelegateExecutionListener (org.camunda.bpm.engine.impl.bpmn.listener.ClassDelegateExecutionListener)1 DelegateExpressionExecutionListener (org.camunda.bpm.engine.impl.bpmn.listener.DelegateExpressionExecutionListener)1 ExpressionExecutionListener (org.camunda.bpm.engine.impl.bpmn.listener.ExpressionExecutionListener)1 ScriptExecutionListener (org.camunda.bpm.engine.impl.bpmn.listener.ScriptExecutionListener)1