Search in sources :

Example 6 with ExecutionListener

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

the class ProcessApplicationEventListenerTest method testExecutionListenerWithTimerBoundaryEvent.

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

        public ExecutionListener getExecutionListener() {
            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());
    // 1. (start)startEvent(end) -(take)-> (start)userTask(end) -(take)-> (start)endEvent(end) (8 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // complete task
    Task task = taskService.createTaskQuery().singleResult();
    taskService.complete(task.getId());
    assertEquals(10, eventCount.get());
    // reset counter
    eventCount.set(0);
    // 2. (start)startEvent(end) -(take)-> (start)userTask(end)/(start)timerBoundaryEvent(end) -(take)-> (start)endEvent(end) (10 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // fire timer event
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    assertEquals(12, eventCount.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) Job(org.camunda.bpm.engine.runtime.Job) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 7 with ExecutionListener

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

the class ProcessApplicationEventListenerDelegate method notifyExecutionListener.

protected void notifyExecutionListener(DelegateExecution execution) throws Exception {
    ProcessApplicationReference processApp = Context.getCurrentProcessApplication();
    try {
        ProcessApplicationInterface processApplication = processApp.getProcessApplication();
        ExecutionListener executionListener = processApplication.getExecutionListener();
        if (executionListener != null) {
            executionListener.notify(execution);
        } else {
            LOG.paDoesNotProvideExecutionListener(processApp.getName());
        }
    } catch (ProcessApplicationUnavailableException e) {
        // Process Application unavailable => ignore silently
        LOG.cannotInvokeListenerPaUnavailable(processApp.getName(), e);
    }
}
Also used : ProcessApplicationReference(org.camunda.bpm.application.ProcessApplicationReference) ProcessApplicationUnavailableException(org.camunda.bpm.application.ProcessApplicationUnavailableException) ProcessApplicationInterface(org.camunda.bpm.application.ProcessApplicationInterface) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener)

Example 8 with ExecutionListener

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

the class BpmnParse method parseExecutionListener.

/**
 * Parses an {@link ExecutionListener} implementation for the given
 * executionListener element.
 *
 * @param executionListenerElement
 *          the XML element containing the executionListener definition.
 */
public ExecutionListener parseExecutionListener(Element executionListenerElement) {
    ExecutionListener executionListener = null;
    String className = executionListenerElement.attribute(PROPERTYNAME_CLASS);
    String expression = executionListenerElement.attribute(PROPERTYNAME_EXPRESSION);
    String delegateExpression = executionListenerElement.attribute(PROPERTYNAME_DELEGATE_EXPRESSION);
    Element scriptElement = executionListenerElement.elementNS(CAMUNDA_BPMN_EXTENSIONS_NS, "script");
    if (className != null) {
        executionListener = new ClassDelegateExecutionListener(className, parseFieldDeclarations(executionListenerElement));
    } else if (expression != null) {
        executionListener = new ExpressionExecutionListener(expressionManager.createExpression(expression));
    } else if (delegateExpression != null) {
        executionListener = new DelegateExpressionExecutionListener(expressionManager.createExpression(delegateExpression), parseFieldDeclarations(executionListenerElement));
    } else if (scriptElement != null) {
        try {
            ExecutableScript executableScript = parseCamundaScript(scriptElement);
            if (executableScript != null) {
                executionListener = new ScriptExecutionListener(executableScript);
            }
        } catch (BpmnParseException e) {
            addError(e);
        }
    } else {
        addError("Element 'class', 'expression', 'delegateExpression' or 'script' is mandatory on executionListener", executionListenerElement);
    }
    return executionListener;
}
Also used : ScriptExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ScriptExecutionListener) BpmnParseException(org.camunda.bpm.engine.BpmnParseException) Element(org.camunda.bpm.engine.impl.util.xml.Element) ClassDelegateExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ClassDelegateExecutionListener) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) DelegateExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.DelegateExpressionExecutionListener) ExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ExpressionExecutionListener) DelegateExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.DelegateExpressionExecutionListener) ClassDelegateExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ClassDelegateExecutionListener) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) ScriptExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ScriptExecutionListener) ExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.ExpressionExecutionListener) DelegateExpressionExecutionListener(org.camunda.bpm.engine.impl.bpmn.listener.DelegateExpressionExecutionListener)

Example 9 with ExecutionListener

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

the class DelegateExpressionExecutionListener method notify.

public void notify(DelegateExecution execution) throws Exception {
    // Note: we can't cache the result of the expression, because the
    // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
    Object delegate = expression.getValue(execution);
    applyFieldDeclaration(fieldDeclarations, delegate);
    if (delegate instanceof ExecutionListener) {
        Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution));
    } else if (delegate instanceof JavaDelegate) {
        Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution));
    } else {
        throw LOG.resolveDelegateExpressionException(expression, ExecutionListener.class, JavaDelegate.class);
    }
}
Also used : JavaDelegateInvocation(org.camunda.bpm.engine.impl.bpmn.delegate.JavaDelegateInvocation) ExecutionListenerInvocation(org.camunda.bpm.engine.impl.bpmn.delegate.ExecutionListenerInvocation) JavaDelegate(org.camunda.bpm.engine.delegate.JavaDelegate) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener)

Example 10 with ExecutionListener

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

the class ProcessApplicationEventListenerTest method testExecutionListenerWithErrorBoundaryEvent.

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

        public ExecutionListener getExecutionListener() {
            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());
    // 1. (start)startEvent(end) -(take)-> (start)serviceTask(end) -(take)-> (start)endEvent(end) (8 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    assertEquals(10, eventCount.get());
    // reset counter
    eventCount.set(0);
    // 2. (start)startEvent(end) -(take)-> (start)serviceTask(end)/(start)errorBoundaryEvent(end) -(take)-> (start)endEvent(end) (10 Events)
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener", Collections.<String, Object>singletonMap("shouldThrowError", true));
    assertEquals(12, 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)

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