Search in sources :

Example 1 with OutgoingExecution

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

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)1 PvmTransition (org.camunda.bpm.engine.impl.pvm.PvmTransition)1 OutgoingExecution (org.camunda.bpm.engine.impl.pvm.runtime.OutgoingExecution)1 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)1