Search in sources :

Example 1 with VariableEvent

use of org.camunda.bpm.engine.impl.core.variable.event.VariableEvent in project camunda-bpm-platform by camunda.

the class ConditionalEventHandler method handleEvent.

@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, String businessKey, CommandContext commandContext) {
    VariableEvent variableEvent;
    if (payload == null || payload instanceof VariableEvent) {
        variableEvent = (VariableEvent) payload;
    } else {
        throw new ProcessEngineException("Payload have to be " + VariableEvent.class.getName() + ", to evaluate condition.");
    }
    ActivityImpl activity = eventSubscription.getActivity();
    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    if (activityBehavior instanceof ConditionalEventBehavior) {
        ConditionalEventBehavior conditionalBehavior = (ConditionalEventBehavior) activityBehavior;
        conditionalBehavior.leaveOnSatisfiedCondition(eventSubscription, variableEvent);
    } else {
        throw new ProcessEngineException("Conditional Event has not correct behavior: " + activityBehavior);
    }
}
Also used : VariableEvent(org.camunda.bpm.engine.impl.core.variable.event.VariableEvent) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior) ConditionalEventBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.ConditionalEventBehavior) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with VariableEvent

use of org.camunda.bpm.engine.impl.core.variable.event.VariableEvent in project camunda-bpm-platform by camunda.

the class CmmnExecution method invokeVariableListeners.

protected void invokeVariableListeners(boolean includeCustomerListeners) {
    Queue<VariableEvent> variableEventsQueue = getVariableEventQueue();
    while (!variableEventsQueue.isEmpty()) {
        // do not remove the event yet, as otherwise new events will immediately be dispatched
        VariableEvent nextEvent = variableEventsQueue.peek();
        CmmnExecution sourceExecution = (CmmnExecution) nextEvent.getSourceScope();
        DelegateCaseVariableInstanceImpl delegateVariable = DelegateCaseVariableInstanceImpl.fromVariableInstance(nextEvent.getVariableInstance());
        delegateVariable.setEventName(nextEvent.getEventName());
        delegateVariable.setSourceExecution(sourceExecution);
        Map<String, List<VariableListener<?>>> listenersByActivity = sourceExecution.getActivity().getVariableListeners(delegateVariable.getEventName(), includeCustomerListeners);
        CmmnExecution currentExecution = sourceExecution;
        while (currentExecution != null) {
            if (currentExecution.getActivityId() != null) {
                List<VariableListener<?>> listeners = listenersByActivity.get(currentExecution.getActivityId());
                if (listeners != null) {
                    delegateVariable.setScopeExecution(currentExecution);
                    for (VariableListener<?> listener : listeners) {
                        try {
                            CaseVariableListener caseVariableListener = (CaseVariableListener) listener;
                            CaseVariableListenerInvocation invocation = new CaseVariableListenerInvocation(caseVariableListener, delegateVariable, currentExecution);
                            Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
                        } catch (Exception e) {
                            throw LOG.invokeVariableListenerException(e);
                        }
                    }
                }
            }
            currentExecution = currentExecution.getParent();
        }
        // finally remove the event from the queue
        variableEventsQueue.remove();
    }
}
Also used : DelegateCaseVariableInstanceImpl(org.camunda.bpm.engine.impl.variable.listener.DelegateCaseVariableInstanceImpl) CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener) VariableListener(org.camunda.bpm.engine.delegate.VariableListener) CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener) PvmException(org.camunda.bpm.engine.impl.pvm.PvmException) VariableEvent(org.camunda.bpm.engine.impl.core.variable.event.VariableEvent) CaseVariableListenerInvocation(org.camunda.bpm.engine.impl.variable.listener.CaseVariableListenerInvocation) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

VariableEvent (org.camunda.bpm.engine.impl.core.variable.event.VariableEvent)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 CaseVariableListener (org.camunda.bpm.engine.delegate.CaseVariableListener)1 VariableListener (org.camunda.bpm.engine.delegate.VariableListener)1 ConditionalEventBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.ConditionalEventBehavior)1 PvmException (org.camunda.bpm.engine.impl.pvm.PvmException)1 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)1 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)1 CaseVariableListenerInvocation (org.camunda.bpm.engine.impl.variable.listener.CaseVariableListenerInvocation)1 DelegateCaseVariableInstanceImpl (org.camunda.bpm.engine.impl.variable.listener.DelegateCaseVariableInstanceImpl)1