Search in sources :

Example 1 with ExecutionListener

use of org.activiti.engine.delegate.ExecutionListener in project Activiti by Activiti.

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);
    ClassDelegate.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 new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + ExecutionListener.class + " nor " + JavaDelegate.class);
    }
}
Also used : JavaDelegateInvocation(org.activiti.engine.impl.delegate.JavaDelegateInvocation) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ExecutionListenerInvocation(org.activiti.engine.impl.delegate.ExecutionListenerInvocation) JavaDelegate(org.activiti.engine.delegate.JavaDelegate) ExecutionListener(org.activiti.engine.delegate.ExecutionListener)

Example 2 with ExecutionListener

use of org.activiti.engine.delegate.ExecutionListener in project Activiti by Activiti.

the class MultiInstanceActivityBehavior method callCustomActivityStartListeners.

/**
   * Since the first loop of the multi instance is not executed as a regular activity,
   * it is needed to call the start listeners yourself.
   */
protected void callCustomActivityStartListeners(ActivityExecution execution) {
    List<ExecutionListener> listeners = activity.getExecutionListeners(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_START);
    List<ExecutionListener> filteredExecutionListeners = new ArrayList<ExecutionListener>(listeners.size());
    if (listeners != null) {
        for (ExecutionListener executionListener : listeners) {
            if (!(executionListener instanceof ActivityInstanceStartHandler)) {
                filteredExecutionListeners.add(executionListener);
            }
        }
        CallActivityListenersOperation atomicOperation = new CallActivityListenersOperation(filteredExecutionListeners);
        Context.getCommandContext().performOperation(atomicOperation, (InterpretableExecution) execution);
    }
}
Also used : ActivityInstanceStartHandler(org.activiti.engine.impl.history.handler.ActivityInstanceStartHandler) ArrayList(java.util.ArrayList) ExecutionListener(org.activiti.engine.delegate.ExecutionListener)

Example 3 with ExecutionListener

use of org.activiti.engine.delegate.ExecutionListener in project Activiti by Activiti.

the class AbstractEventAtomicOperation method execute.

public void execute(InterpretableExecution execution) {
    ScopeImpl scope = getScope(execution);
    List<ExecutionListener> exectionListeners = scope.getExecutionListeners(getEventName());
    int executionListenerIndex = execution.getExecutionListenerIndex();
    if (exectionListeners.size() > executionListenerIndex) {
        execution.setEventName(getEventName());
        execution.setEventSource(scope);
        ExecutionListener listener = exectionListeners.get(executionListenerIndex);
        try {
            listener.notify(execution);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new PvmException("couldn't execute event listener : " + e.getMessage(), e);
        }
        execution.setExecutionListenerIndex(executionListenerIndex + 1);
        execution.performOperation(this);
    } else {
        execution.setExecutionListenerIndex(0);
        execution.setEventName(null);
        execution.setEventSource(null);
        eventNotificationsCompleted(execution);
    }
}
Also used : ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl) PvmException(org.activiti.engine.impl.pvm.PvmException) PvmException(org.activiti.engine.impl.pvm.PvmException) ExecutionListener(org.activiti.engine.delegate.ExecutionListener)

Example 4 with ExecutionListener

use of org.activiti.engine.delegate.ExecutionListener in project Activiti by Activiti.

the class AtomicOperationTransitionNotifyListenerTake method execute.

public void execute(InterpretableExecution execution) {
    TransitionImpl transition = execution.getTransition();
    List<ExecutionListener> executionListeners = transition.getExecutionListeners();
    int executionListenerIndex = execution.getExecutionListenerIndex();
    if (executionListeners.size() > executionListenerIndex) {
        execution.setEventName(org.activiti.engine.impl.pvm.PvmEvent.EVENTNAME_TAKE);
        execution.setEventSource(transition);
        ExecutionListener listener = executionListeners.get(executionListenerIndex);
        try {
            listener.notify(execution);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new PvmException("couldn't execute event listener : " + e.getMessage(), e);
        }
        execution.setExecutionListenerIndex(executionListenerIndex + 1);
        execution.performOperation(this);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("{} takes transition {}", execution, transition);
        }
        execution.setExecutionListenerIndex(0);
        execution.setEventName(null);
        execution.setEventSource(null);
        ActivityImpl activity = (ActivityImpl) execution.getActivity();
        ActivityImpl nextScope = findNextScope(activity.getParent(), transition.getDestination());
        execution.setActivity(nextScope);
        // Firing event that transition is being taken     	
        if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
            Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createSequenceFlowTakenEvent(ActivitiEventType.SEQUENCEFLOW_TAKEN, transition.getId(), activity.getId(), (String) activity.getProperties().get("name"), (String) activity.getProperties().get("type"), activity.getActivityBehavior().getClass().getCanonicalName(), nextScope.getId(), (String) nextScope.getProperties().get("name"), (String) nextScope.getProperties().get("type"), nextScope.getActivityBehavior().getClass().getCanonicalName()));
        }
        execution.performOperation(TRANSITION_CREATE_SCOPE);
    }
}
Also used : TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) PvmException(org.activiti.engine.impl.pvm.PvmException) PvmException(org.activiti.engine.impl.pvm.PvmException) ExecutionListener(org.activiti.engine.delegate.ExecutionListener)

Aggregations

ExecutionListener (org.activiti.engine.delegate.ExecutionListener)4 PvmException (org.activiti.engine.impl.pvm.PvmException)2 ArrayList (java.util.ArrayList)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 JavaDelegate (org.activiti.engine.delegate.JavaDelegate)1 ExecutionListenerInvocation (org.activiti.engine.impl.delegate.ExecutionListenerInvocation)1 JavaDelegateInvocation (org.activiti.engine.impl.delegate.JavaDelegateInvocation)1 ActivityInstanceStartHandler (org.activiti.engine.impl.history.handler.ActivityInstanceStartHandler)1 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)1 TransitionImpl (org.activiti.engine.impl.pvm.process.TransitionImpl)1