Search in sources :

Example 6 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class ThrowSignalEventActivityBehavior method execute.

@Override
public void execute(ActivityExecution execution) throws Exception {
    String businessKey = signalDefinition.getEventPayload().getBusinessKey(execution);
    VariableMap variableMap = signalDefinition.getEventPayload().getInputVariables(execution);
    String eventName = signalDefinition.resolveExpressionOfEventName(execution);
    // trigger all event subscriptions for the signal (start and intermediate)
    List<EventSubscriptionEntity> signalEventSubscriptions = findSignalEventSubscriptions(eventName, execution.getTenantId());
    for (EventSubscriptionEntity signalEventSubscription : signalEventSubscriptions) {
        if (isActiveEventSubscription(signalEventSubscription)) {
            signalEventSubscription.eventReceived(variableMap, businessKey, signalDefinition.isAsync());
        }
    }
    leave(execution);
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 7 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class CompensationUtil method createEventScopeExecution.

/**
 * creates an event scope for the given execution:
 *
 * create a new event scope execution under the parent of the given execution
 * and move all event subscriptions to that execution.
 *
 * this allows us to "remember" the event subscriptions after finishing a
 * scope
 */
public static void createEventScopeExecution(ExecutionEntity execution) {
    // parent execution is a subprocess or a miBody
    ActivityImpl activity = execution.getActivity();
    ExecutionEntity scopeExecution = (ExecutionEntity) execution.findExecutionForFlowScope(activity.getFlowScope());
    List<EventSubscriptionEntity> eventSubscriptions = execution.getCompensateEventSubscriptions();
    if (eventSubscriptions.size() > 0 || hasCompensationEventSubprocess(activity)) {
        ExecutionEntity eventScopeExecution = scopeExecution.createExecution();
        eventScopeExecution.setActivity(execution.getActivity());
        eventScopeExecution.activityInstanceStarting();
        eventScopeExecution.enterActivityInstance();
        eventScopeExecution.setActive(false);
        eventScopeExecution.setConcurrent(false);
        eventScopeExecution.setEventScope(true);
        // copy local variables to eventScopeExecution by value. This way,
        // the eventScopeExecution references a 'snapshot' of the local variables
        Map<String, Object> variables = execution.getVariablesLocal();
        for (Entry<String, Object> variable : variables.entrySet()) {
            eventScopeExecution.setVariableLocal(variable.getKey(), variable.getValue());
        }
        // set event subscriptions to the event scope execution:
        for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
            EventSubscriptionEntity newSubscription = EventSubscriptionEntity.createAndInsert(eventScopeExecution, EventType.COMPENSATE, eventSubscriptionEntity.getActivity());
            newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration());
            // use the original date
            newSubscription.setCreated(eventSubscriptionEntity.getCreated());
        }
        // (ensuring they don't get removed when 'execution' gets removed)
        for (PvmExecutionImpl childEventScopeExecution : execution.getEventScopeExecutions()) {
            childEventScopeExecution.setParent(eventScopeExecution);
        }
        ActivityImpl compensationHandler = getEventScopeCompensationHandler(execution);
        EventSubscriptionEntity eventSubscription = EventSubscriptionEntity.createAndInsert(scopeExecution, EventType.COMPENSATE, compensationHandler);
        eventSubscription.setConfiguration(eventScopeExecution.getId());
    }
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 8 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class CompensationUtil method throwCompensationEvent.

/**
 * we create a separate execution for each compensation handler invocation.
 */
public static void throwCompensationEvent(List<EventSubscriptionEntity> eventSubscriptions, ActivityExecution execution, boolean async) {
    // first spawn the compensating executions
    for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
        // check whether compensating execution is already created
        // (which is the case when compensating an embedded subprocess,
        // where the compensating execution is created when leaving the subprocess
        // and holds snapshot data).
        ExecutionEntity compensatingExecution = getCompensatingExecution(eventSubscription);
        if (compensatingExecution != null) {
            if (compensatingExecution.getParent() != execution) {
                // move the compensating execution under this execution if this is not the case yet
                compensatingExecution.setParent((PvmExecutionImpl) execution);
            }
            compensatingExecution.setEventScope(false);
        } else {
            compensatingExecution = (ExecutionEntity) execution.createExecution();
            eventSubscription.setConfiguration(compensatingExecution.getId());
        }
        compensatingExecution.setConcurrent(true);
    }
    // signal compensation events in REVERSE order of their 'created' timestamp
    Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() {

        @Override
        public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) {
            return o2.getCreated().compareTo(o1.getCreated());
        }
    });
    for (EventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) {
        compensateEventSubscriptionEntity.eventReceived(null, async);
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 9 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class CompensationUtil method collectCompensateEventSubscriptionsForActivity.

/**
 * Collect all compensate event subscriptions for activity on the scope of
 * given execution.
 */
public static List<EventSubscriptionEntity> collectCompensateEventSubscriptionsForActivity(ActivityExecution execution, String activityRef) {
    final List<EventSubscriptionEntity> eventSubscriptions = collectCompensateEventSubscriptionsForScope(execution);
    final String subscriptionActivityId = getSubscriptionActivityId(execution, activityRef);
    List<EventSubscriptionEntity> eventSubscriptionsForActivity = new ArrayList<EventSubscriptionEntity>();
    for (EventSubscriptionEntity subscription : eventSubscriptions) {
        if (subscriptionActivityId.equals(subscription.getActivityId())) {
            eventSubscriptionsForActivity.add(subscription);
        }
    }
    return eventSubscriptionsForActivity;
}
Also used : ArrayList(java.util.ArrayList) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 10 with EventSubscriptionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity in project camunda-bpm-platform by camunda.

the class EventSubscriptionDeclaration method createSubscriptionForStartEvent.

public EventSubscriptionEntity createSubscriptionForStartEvent(ProcessDefinitionEntity processDefinition) {
    EventSubscriptionEntity eventSubscriptionEntity = new EventSubscriptionEntity(eventType);
    VariableScope scopeForExpression = StartProcessVariableScope.getSharedInstance();
    String eventName = resolveExpressionOfEventName(scopeForExpression);
    eventSubscriptionEntity.setEventName(eventName);
    eventSubscriptionEntity.setActivityId(activityId);
    eventSubscriptionEntity.setConfiguration(processDefinition.getId());
    eventSubscriptionEntity.setTenantId(processDefinition.getTenantId());
    return eventSubscriptionEntity;
}
Also used : EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) VariableScope(org.camunda.bpm.engine.delegate.VariableScope) StartProcessVariableScope(org.camunda.bpm.engine.impl.el.StartProcessVariableScope)

Aggregations

EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)33 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)8 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)7 ArrayList (java.util.ArrayList)6 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)5 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)4 EventSubscription (org.camunda.bpm.engine.runtime.EventSubscription)4 Deployment (org.camunda.bpm.engine.test.Deployment)4 EventSubscriptionManager (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionManager)3 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)2 MigratingActivityInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance)2 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)2 CompositeActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior)2 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)2 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 VariableScope (org.camunda.bpm.engine.delegate.VariableScope)1