Search in sources :

Example 11 with PvmExecutionImpl

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

the class PvmAtomicOperationCancelActivity method execute.

public void execute(PvmExecutionImpl execution) {
    // Assumption: execution is scope
    PvmActivity cancellingActivity = execution.getNextActivity();
    execution.setNextActivity(null);
    // first, cancel and destroy the current scope
    execution.setActive(true);
    PvmExecutionImpl propagatingExecution = null;
    if (LegacyBehavior.isConcurrentScope(execution)) {
        // this is legacy behavior
        LegacyBehavior.cancelConcurrentScope(execution, (PvmActivity) cancellingActivity.getEventScope());
        propagatingExecution = execution;
    } else {
        // Unlike PvmAtomicOperationTransitionDestroyScope this needs to use delete() (instead of destroy() and remove()).
        // The reason is that PvmAtomicOperationTransitionDestroyScope is executed when a scope (or non scope) is left using
        // a sequence flow. In that case the execution will have completed all the work inside the current activity
        // and will have no more child executions. In PvmAtomicOperationCancelScope the scope is cancelled due to
        // a boundary event firing. In that case the execution has not completed all the work in the current scope / activity
        // and it is necessary to delete the complete hierarchy of executions below and including the execution itself.
        execution.deleteCascade("Cancel scope activity " + cancellingActivity + " executed.");
        propagatingExecution = execution.getParent();
    }
    propagatingExecution.setActivity(cancellingActivity);
    propagatingExecution.setActive(true);
    propagatingExecution.setEnded(false);
    activityCancelled(propagatingExecution);
}
Also used : PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 12 with PvmExecutionImpl

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

the class PvmAtomicOperationCreateScope method execute.

public void execute(PvmExecutionImpl execution) {
    // reset activity instance id before creating the scope
    execution.setActivityInstanceId(execution.getParentActivityInstanceId());
    PvmExecutionImpl propagatingExecution = null;
    PvmActivity activity = execution.getActivity();
    if (activity.isScope()) {
        propagatingExecution = execution.createExecution();
        propagatingExecution.setActivity(activity);
        propagatingExecution.setTransition(execution.getTransition());
        execution.setTransition(null);
        execution.setActive(false);
        execution.setActivity(null);
        LOG.createScope(execution, propagatingExecution);
        propagatingExecution.initialize();
    } else {
        propagatingExecution = execution;
    }
    scopeCreated(propagatingExecution);
}
Also used : PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 13 with PvmExecutionImpl

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

the class PvmAtomicOperationDeleteCascadeFireActivityEnd method eventNotificationsCompleted.

@Override
protected void eventNotificationsCompleted(PvmExecutionImpl execution) {
    PvmActivity activity = execution.getActivity();
    if (execution.isScope() && (executesNonScopeActivity(execution) || isAsyncBeforeActivity(execution)) && !CompensationBehavior.executesNonScopeCompensationHandler(execution)) {
        execution.removeAllTasks();
        // case this is a scope execution and the activity is not a scope
        execution.leaveActivityInstance();
        execution.setActivity(getFlowScopeActivity(activity));
        execution.performOperation(DELETE_CASCADE_FIRE_ACTIVITY_END);
    } else {
        if (execution.isScope()) {
            execution.destroy();
        }
        // remove this execution and its concurrent parent (if exists)
        execution.remove();
        boolean continueRemoval = !execution.isDeleteRoot();
        if (continueRemoval) {
            PvmExecutionImpl propagatingExecution = execution.getParent();
            if (propagatingExecution != null && !propagatingExecution.isScope() && !propagatingExecution.hasChildren()) {
                propagatingExecution.remove();
                continueRemoval = !propagatingExecution.isDeleteRoot();
                propagatingExecution = propagatingExecution.getParent();
            }
            if (continueRemoval) {
                if (propagatingExecution != null) {
                    // set activity on parent in case the parent is an inactive scope execution and activity has been set to 'null'.
                    if (propagatingExecution.getActivity() == null && activity != null && activity.getFlowScope() != null) {
                        propagatingExecution.setActivity(getFlowScopeActivity(activity));
                    }
                }
            }
        }
    }
}
Also used : PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 14 with PvmExecutionImpl

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

the class PvmAtomicOperationProcessEnd method eventNotificationsCompleted.

@Override
protected void eventNotificationsCompleted(PvmExecutionImpl execution) {
    execution.leaveActivityInstance();
    PvmExecutionImpl superExecution = execution.getSuperExecution();
    CmmnActivityExecution superCaseExecution = execution.getSuperCaseExecution();
    SubProcessActivityBehavior subProcessActivityBehavior = null;
    TransferVariablesActivityBehavior transferVariablesBehavior = null;
    // copy variables before destroying the ended sub process instance
    if (superExecution != null) {
        PvmActivity activity = superExecution.getActivity();
        subProcessActivityBehavior = (SubProcessActivityBehavior) activity.getActivityBehavior();
        try {
            subProcessActivityBehavior.passOutputVariables(superExecution, execution);
        } catch (RuntimeException e) {
            LOG.exceptionWhileCompletingSupProcess(execution, e);
            throw e;
        } catch (Exception e) {
            LOG.exceptionWhileCompletingSupProcess(execution, e);
            throw new ProcessEngineException("Error while completing sub process of execution " + execution, e);
        }
    } else if (superCaseExecution != null) {
        CmmnActivity activity = superCaseExecution.getActivity();
        transferVariablesBehavior = (TransferVariablesActivityBehavior) activity.getActivityBehavior();
        try {
            transferVariablesBehavior.transferVariables(execution, superCaseExecution);
        } catch (RuntimeException e) {
            LOG.exceptionWhileCompletingSupProcess(execution, e);
            throw e;
        } catch (Exception e) {
            LOG.exceptionWhileCompletingSupProcess(execution, e);
            throw new ProcessEngineException("Error while completing sub process of execution " + execution, e);
        }
    }
    execution.destroy();
    execution.remove();
    // and trigger execution afterwards
    if (superExecution != null) {
        superExecution.setSubProcessInstance(null);
        try {
            subProcessActivityBehavior.completed(superExecution);
        } catch (RuntimeException e) {
            LOG.exceptionWhileCompletingSupProcess(execution, e);
            throw e;
        } catch (Exception e) {
            LOG.exceptionWhileCompletingSupProcess(execution, e);
            throw new ProcessEngineException("Error while completing sub process of execution " + execution, e);
        }
    } else if (superCaseExecution != null) {
        superCaseExecution.complete();
    }
}
Also used : CmmnActivityExecution(org.camunda.bpm.engine.impl.cmmn.execution.CmmnActivityExecution) TransferVariablesActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.TransferVariablesActivityBehavior) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) SubProcessActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.SubProcessActivityBehavior)

Example 15 with PvmExecutionImpl

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

the class PvmAtomicOperationTransitionDestroyScope method execute.

public void execute(PvmExecutionImpl execution) {
    // calculate the propagating execution
    PvmExecutionImpl propagatingExecution = execution;
    PvmActivity activity = execution.getActivity();
    List<PvmTransition> transitionsToTake = execution.getTransitionsToTake();
    execution.setTransitionsToTake(null);
    // check whether the current scope needs to be destroyed
    if (execution.isScope() && activity.isScope()) {
        if (!LegacyBehavior.destroySecondNonScope(execution)) {
            if (execution.isConcurrent()) {
                // legacy behavior
                LegacyBehavior.destroyConcurrentScope(execution);
            } else {
                propagatingExecution = execution.getParent();
                LOG.debugDestroyScope(execution, propagatingExecution);
                execution.destroy();
                propagatingExecution.setActivity(execution.getActivity());
                propagatingExecution.setTransition(execution.getTransition());
                propagatingExecution.setActive(true);
                execution.remove();
            }
        }
    } else {
        // activity is not scope => nothing to do
        propagatingExecution = execution;
    }
    // take the specified transitions
    if (transitionsToTake.isEmpty()) {
        throw new ProcessEngineException(execution.toString() + ": No outgoing transitions from " + "activity " + activity);
    } else if (transitionsToTake.size() == 1) {
        propagatingExecution.setTransition(transitionsToTake.get(0));
        propagatingExecution.take();
    } else {
        propagatingExecution.inactivate();
        List<OutgoingExecution> outgoingExecutions = new ArrayList<OutgoingExecution>();
        for (int i = 0; i < transitionsToTake.size(); i++) {
            PvmTransition transition = transitionsToTake.get(i);
            PvmExecutionImpl scopeExecution = propagatingExecution.isScope() ? propagatingExecution : propagatingExecution.getParent();
            // reuse concurrent, propagating execution for first transition
            PvmExecutionImpl concurrentExecution = null;
            if (i == 0) {
                concurrentExecution = propagatingExecution;
            } else {
                concurrentExecution = scopeExecution.createConcurrentExecution();
                if (i == 1 && !propagatingExecution.isConcurrent()) {
                    outgoingExecutions.remove(0);
                    // get a hold of the concurrent execution that replaced the scope propagating execution
                    PvmExecutionImpl replacingExecution = null;
                    for (PvmExecutionImpl concurrentChild : scopeExecution.getNonEventScopeExecutions()) {
                        if (!(concurrentChild == propagatingExecution)) {
                            replacingExecution = concurrentChild;
                            break;
                        }
                    }
                    outgoingExecutions.add(new OutgoingExecution(replacingExecution, transitionsToTake.get(0)));
                }
            }
            outgoingExecutions.add(new OutgoingExecution(concurrentExecution, transition));
        }
        // start executions in reverse order (order will be reversed again in command context with the effect that they are
        // actually be started in correct order :) )
        Collections.reverse(outgoingExecutions);
        for (OutgoingExecution outgoingExecution : outgoingExecutions) {
            outgoingExecution.take();
        }
    }
}
Also used : PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) List(java.util.List) ArrayList(java.util.ArrayList) OutgoingExecution(org.camunda.bpm.engine.impl.pvm.runtime.OutgoingExecution) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

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