Search in sources :

Example 11 with EventSubscriptionEntity

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

the class SignalEventReceivedCmd method startProcessInstances.

private void startProcessInstances(List<EventSubscriptionEntity> startSignalEventSubscriptions, Map<String, ProcessDefinitionEntity> processDefinitions) {
    for (EventSubscriptionEntity signalStartEventSubscription : startSignalEventSubscriptions) {
        ProcessDefinitionEntity processDefinition = processDefinitions.get(signalStartEventSubscription.getId());
        if (processDefinition != null) {
            ActivityImpl signalStartEvent = processDefinition.findActivity(signalStartEventSubscription.getActivityId());
            PvmProcessInstance processInstance = processDefinition.createProcessInstanceForInitial(signalStartEvent);
            processInstance.start(builder.getVariables());
        }
    }
}
Also used : PvmProcessInstance(org.camunda.bpm.engine.impl.pvm.PvmProcessInstance) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 12 with EventSubscriptionEntity

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

the class SignalEventReceivedCmd method sendSignalToExecution.

protected void sendSignalToExecution(CommandContext commandContext, String signalName, String executionId) {
    ExecutionManager executionManager = commandContext.getExecutionManager();
    ExecutionEntity execution = executionManager.findExecutionById(executionId);
    ensureNotNull("Cannot find execution with id '" + executionId + "'", "execution", execution);
    EventSubscriptionManager eventSubscriptionManager = commandContext.getEventSubscriptionManager();
    List<EventSubscriptionEntity> signalEvents = eventSubscriptionManager.findSignalEventSubscriptionsByNameAndExecution(signalName, executionId);
    ensureNotEmpty("Execution '" + executionId + "' has not subscribed to a signal event with name '" + signalName + "'.", signalEvents);
    checkAuthorizationOfCatchSignals(commandContext, signalEvents);
    notifyExecutions(signalEvents);
}
Also used : EventSubscriptionManager(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionManager) ExecutionManager(org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 13 with EventSubscriptionEntity

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

the class CompensationEventHandler method handleEvent.

@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, String businessKey, CommandContext commandContext) {
    eventSubscription.delete();
    String configuration = eventSubscription.getConfiguration();
    ensureNotNull("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId(), "configuration", configuration);
    ExecutionEntity compensatingExecution = commandContext.getExecutionManager().findExecutionById(configuration);
    ActivityImpl compensationHandler = eventSubscription.getActivity();
    // activate execution
    compensatingExecution.setActive(true);
    if (compensatingExecution.getActivity().getActivityBehavior() instanceof CompositeActivityBehavior) {
        compensatingExecution.getParent().setActivityInstanceId(compensatingExecution.getActivityInstanceId());
    }
    if (compensationHandler.isScope() && !compensationHandler.isCompensationHandler()) {
        // descend into scope:
        List<EventSubscriptionEntity> eventsForThisScope = compensatingExecution.getCompensateEventSubscriptions();
        CompensationUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);
    } else {
        try {
            if (compensationHandler.isSubProcessScope() && compensationHandler.isTriggeredByEvent()) {
                compensatingExecution.executeActivity(compensationHandler);
            } else {
                // since we already have a scope execution, we don't need to create another one
                // for a simple scoped compensation handler
                compensatingExecution.setActivity(compensationHandler);
                compensatingExecution.performOperation(PvmAtomicOperation.ACTIVITY_START);
            }
        } catch (Exception e) {
            throw new ProcessEngineException("Error while handling compensation event " + eventSubscription, e);
        }
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 14 with EventSubscriptionEntity

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

the class LegacyBehavior method removeLegacySubscriptionOnParent.

/**
 * <p>Required for migrating active sequential MI receive tasks. These activities were formerly not scope,
 * but are now. This has the following implications:
 *
 * <p>Before migration:
 * <ul><li> the event subscription is attached to the miBody scope execution</ul>
 *
 * <p>After migration:
 * <ul><li> a new subscription is created for every instance
 * <li> the new subscription is attached to a dedicated scope execution as a child of the miBody scope
 *   execution</ul>
 *
 * <p>Thus, this method removes the subscription on the miBody scope
 */
public static void removeLegacySubscriptionOnParent(ExecutionEntity execution, EventSubscriptionEntity eventSubscription) {
    ActivityImpl activity = execution.getActivity();
    if (activity == null) {
        return;
    }
    ActivityBehavior behavior = activity.getActivityBehavior();
    ActivityBehavior parentBehavior = (ActivityBehavior) (activity.getFlowScope() != null ? activity.getFlowScope().getActivityBehavior() : null);
    if (behavior instanceof ReceiveTaskActivityBehavior && parentBehavior instanceof MultiInstanceActivityBehavior) {
        List<EventSubscriptionEntity> parentSubscriptions = execution.getParent().getEventSubscriptions();
        for (EventSubscriptionEntity subscription : parentSubscriptions) {
            // distinguish a boundary event on the mi body with the same message name from the receive task subscription
            if (areEqualEventSubscriptions(subscription, eventSubscription)) {
                subscription.delete();
            }
        }
    }
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ReceiveTaskActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.ReceiveTaskActivityBehavior) CancelBoundaryEventActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.CancelBoundaryEventActivityBehavior) SubProcessActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.SubProcessActivityBehavior) MultiInstanceActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior) ReceiveTaskActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.ReceiveTaskActivityBehavior) CompensationEventActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.CompensationEventActivityBehavior) EventSubProcessActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.EventSubProcessActivityBehavior) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) SequentialMultiInstanceActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.SequentialMultiInstanceActivityBehavior) ActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior) CancelEndEventActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.CancelEndEventActivityBehavior) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) MultiInstanceActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior) SequentialMultiInstanceActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.SequentialMultiInstanceActivityBehavior)

Example 15 with EventSubscriptionEntity

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

the class DefaultConditionHandler method evaluateConditionStartByEventSubscription.

protected List<ConditionHandlerResult> evaluateConditionStartByEventSubscription(CommandContext commandContext, ConditionSet conditionSet) {
    List<EventSubscriptionEntity> subscriptions = findConditionalStartEventSubscriptions(commandContext, conditionSet);
    if (subscriptions.isEmpty()) {
        throw LOG.exceptionWhenEvaluatingConditionalStartEvent();
    }
    List<ConditionHandlerResult> results = new ArrayList<ConditionHandlerResult>();
    for (EventSubscriptionEntity subscription : subscriptions) {
        ProcessDefinitionEntity processDefinition = subscription.getProcessDefinition();
        if (!processDefinition.isSuspended()) {
            ActivityImpl activity = subscription.getActivity();
            if (evaluateCondition(conditionSet, activity)) {
                results.add(new ConditionHandlerResult(processDefinition, activity));
            }
        }
    }
    return results;
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ArrayList(java.util.ArrayList) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)

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