Search in sources :

Example 6 with PvmExecutionImpl

use of org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl 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 7 with PvmExecutionImpl

use of org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl in project camunda-bpm-platform by camunda.

the class AbstractBpmnActivityBehavior method propagateError.

protected void propagateError(String errorCode, String errorMessage, Exception origException, ActivityExecution execution) throws Exception {
    ActivityExecutionHierarchyWalker walker = new ActivityExecutionHierarchyWalker(execution);
    final ErrorDeclarationForProcessInstanceFinder errorDeclarationFinder = new ErrorDeclarationForProcessInstanceFinder(origException, errorCode, execution.getActivity());
    ActivityExecutionMappingCollector activityExecutionMappingCollector = new ActivityExecutionMappingCollector(execution);
    walker.addScopePreVisitor(errorDeclarationFinder);
    walker.addExecutionPreVisitor(activityExecutionMappingCollector);
    // map variables to super executions in the hierarchy of called process instances
    walker.addExecutionPreVisitor(new OutputVariablesPropagator());
    try {
        walker.walkUntil(new ReferenceWalker.WalkCondition<ActivityExecutionTuple>() {

            @Override
            public boolean isFulfilled(ActivityExecutionTuple element) {
                return errorDeclarationFinder.getErrorEventDefinition() != null || element == null;
            }
        });
    } catch (Exception e) {
        // separate the exception handling to support a fail-safe error propagation
        throw new ErrorPropagationException(e);
    }
    PvmActivity errorHandlingActivity = errorDeclarationFinder.getErrorHandlerActivity();
    // process the error
    if (errorHandlingActivity == null) {
        if (origException == null) {
            if (Context.getCommandContext().getProcessEngineConfiguration().isEnableExceptionsAfterUnhandledBpmnError()) {
                throw LOG.missingBoundaryCatchEventError(execution.getActivity().getId(), errorCode);
            } else {
                LOG.missingBoundaryCatchEvent(execution.getActivity().getId(), errorCode);
                execution.end(true);
            }
        } else {
            // throw original exception
            throw origException;
        }
    } else {
        ErrorEventDefinition errorDefinition = errorDeclarationFinder.getErrorEventDefinition();
        PvmExecutionImpl errorHandlingExecution = activityExecutionMappingCollector.getExecutionForScope(errorHandlingActivity.getEventScope());
        if (errorDefinition.getErrorCodeVariable() != null) {
            errorHandlingExecution.setVariable(errorDefinition.getErrorCodeVariable(), errorCode);
        }
        if (errorDefinition.getErrorMessageVariable() != null) {
            errorHandlingExecution.setVariable(errorDefinition.getErrorMessageVariable(), errorMessage);
        }
        errorHandlingExecution.executeActivity(errorHandlingActivity);
    }
}
Also used : ActivityExecutionMappingCollector(org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) OutputVariablesPropagator(org.camunda.bpm.engine.impl.tree.OutputVariablesPropagator) ActivityExecutionTuple(org.camunda.bpm.engine.impl.tree.ActivityExecutionTuple) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ActivityExecutionHierarchyWalker(org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker) ReferenceWalker(org.camunda.bpm.engine.impl.tree.ReferenceWalker) ErrorEventDefinition(org.camunda.bpm.engine.impl.bpmn.parser.ErrorEventDefinition)

Example 8 with PvmExecutionImpl

use of org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl in project camunda-bpm-platform by camunda.

the class AbstractAtomicOperationCaseExecutionComplete method postTransitionNotification.

protected void postTransitionNotification(CmmnExecution execution) {
    if (!execution.isCaseInstanceExecution()) {
        execution.remove();
    } else {
        CmmnExecution superCaseExecution = execution.getSuperCaseExecution();
        PvmExecutionImpl superExecution = execution.getSuperExecution();
        if (superCaseExecution != null) {
            TransferVariablesActivityBehavior behavior = (TransferVariablesActivityBehavior) getActivityBehavior(superCaseExecution);
            behavior.transferVariables(execution, superCaseExecution);
            superCaseExecution.complete();
        } else if (superExecution != null) {
            SubProcessActivityBehavior behavior = (SubProcessActivityBehavior) getActivityBehavior(superExecution);
            try {
                behavior.passOutputVariables(superExecution, execution);
            } catch (RuntimeException e) {
                LOG.completingSubCaseError(execution, e);
                throw e;
            } catch (Exception e) {
                LOG.completingSubCaseError(execution, e);
                throw LOG.completingSubCaseErrorException(execution, e);
            }
            // set sub case instance to null
            superExecution.setSubCaseInstance(null);
            try {
                behavior.completed(superExecution);
            } catch (RuntimeException e) {
                LOG.completingSubCaseError(execution, e);
                throw e;
            } catch (Exception e) {
                LOG.completingSubCaseError(execution, e);
                throw LOG.completingSubCaseErrorException(execution, e);
            }
        }
        execution.setSuperCaseExecution(null);
        execution.setSuperExecution(null);
    }
    CmmnExecution parent = execution.getParent();
    if (parent != null) {
        CmmnActivityBehavior behavior = getActivityBehavior(parent);
        if (behavior instanceof CmmnCompositeActivityBehavior) {
            CmmnCompositeActivityBehavior compositeBehavior = (CmmnCompositeActivityBehavior) behavior;
            compositeBehavior.handleChildCompletion(parent, execution);
        }
    }
}
Also used : CmmnCompositeActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.CmmnCompositeActivityBehavior) TransferVariablesActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.TransferVariablesActivityBehavior) CmmnActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.CmmnActivityBehavior) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) CmmnExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnExecution) SubProcessActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.SubProcessActivityBehavior)

Example 9 with PvmExecutionImpl

use of org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl in project camunda-bpm-platform by camunda.

the class PvmAtomicOperationActivityEnd method execute.

public void execute(PvmExecutionImpl execution) {
    // restore activity instance id
    if (execution.getActivityInstanceId() == null) {
        execution.setActivityInstanceId(execution.getParentActivityInstanceId());
    }
    PvmActivity activity = execution.getActivity();
    Map<ScopeImpl, PvmExecutionImpl> activityExecutionMapping = execution.createActivityExecutionMapping();
    PvmExecutionImpl propagatingExecution = execution;
    if (execution.isScope() && activity.isScope()) {
        if (!LegacyBehavior.destroySecondNonScope(execution)) {
            execution.destroy();
            if (!execution.isConcurrent()) {
                execution.remove();
                propagatingExecution = execution.getParent();
                propagatingExecution.setActivity(execution.getActivity());
            }
        }
    }
    propagatingExecution = LegacyBehavior.determinePropagatingExecutionOnEnd(propagatingExecution, activityExecutionMapping);
    PvmScope flowScope = activity.getFlowScope();
    // 1. flow scope = Process Definition
    if (flowScope == activity.getProcessDefinition()) {
        // 1.1 concurrent execution => end + tryPrune()
        if (propagatingExecution.isConcurrent()) {
            propagatingExecution.remove();
            propagatingExecution.getParent().tryPruneLastConcurrentChild();
            propagatingExecution.getParent().forceUpdate();
        } else {
            // 1.2 Process End
            propagatingExecution.setEnded(true);
            if (!propagatingExecution.isPreserveScope()) {
                propagatingExecution.performOperation(PROCESS_END);
            }
        }
    } else {
        // 2. flowScope != process definition
        PvmActivity flowScopeActivity = (PvmActivity) flowScope;
        ActivityBehavior activityBehavior = flowScopeActivity.getActivityBehavior();
        if (activityBehavior instanceof CompositeActivityBehavior) {
            CompositeActivityBehavior compositeActivityBehavior = (CompositeActivityBehavior) activityBehavior;
            // 2.1 Concurrent execution => composite behavior.concurrentExecutionEnded()
            if (propagatingExecution.isConcurrent() && !LegacyBehavior.isConcurrentScope(propagatingExecution)) {
                compositeActivityBehavior.concurrentChildExecutionEnded(propagatingExecution.getParent(), propagatingExecution);
            } else {
                // 2.2 Scope Execution => composite behavior.complete()
                propagatingExecution.setActivity(flowScopeActivity);
                compositeActivityBehavior.complete(propagatingExecution);
            }
        } else {
            // activity behavior is not composite => this is unexpected
            throw new ProcessEngineException("Expected behavior of composite scope " + activity + " to be a CompositeActivityBehavior but got " + activityBehavior);
        }
    }
}
Also used : PvmScope(org.camunda.bpm.engine.impl.pvm.PvmScope) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) ActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 10 with PvmExecutionImpl

use of org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl in project camunda-bpm-platform by camunda.

the class PvmAtomicOperationActivityInstanceStart method eventNotificationsCompleted.

protected void eventNotificationsCompleted(PvmExecutionImpl execution) {
    // hack around execution tree structure not being in sync with activity instance concept:
    // if we start a scope activity, remember current activity instance in parent
    PvmExecutionImpl parent = execution.getParent();
    PvmActivity activity = execution.getActivity();
    if (parent != null && execution.isScope() && activity.isScope() && canHaveChildScopes(execution)) {
        parent.setActivityInstanceId(execution.getActivityInstanceId());
    }
}
Also used : PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Aggregations

PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)38 PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)13 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)7 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)7 ArrayList (java.util.ArrayList)6 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 Map (java.util.Map)3 PvmTransition (org.camunda.bpm.engine.impl.pvm.PvmTransition)3 ActivityExecution (org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution)3 SubProcessActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.SubProcessActivityBehavior)3 HashMap (java.util.HashMap)2 TransferVariablesActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.TransferVariablesActivityBehavior)2 ActivityInstanceImpl (org.camunda.bpm.engine.impl.persistence.entity.ActivityInstanceImpl)2 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)2 ProcessDefinitionBuilder (org.camunda.bpm.engine.impl.pvm.ProcessDefinitionBuilder)2 PvmProcessDefinition (org.camunda.bpm.engine.impl.pvm.PvmProcessDefinition)2 PvmProcessInstance (org.camunda.bpm.engine.impl.pvm.PvmProcessInstance)2 PvmScope (org.camunda.bpm.engine.impl.pvm.PvmScope)2 CompositeActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior)2