Search in sources :

Example 16 with PvmActivity

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

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

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

Example 19 with PvmActivity

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

the class MigratingActivityInstanceVisitor method instantiateScopes.

protected void instantiateScopes(MigratingScopeInstance ancestorScopeInstance, MigratingScopeInstanceBranch executionBranch, List<ScopeImpl> scopesToInstantiate) {
    if (scopesToInstantiate.isEmpty()) {
        return;
    }
    // must always be an activity instance
    MigratingActivityInstance ancestorActivityInstance = (MigratingActivityInstance) ancestorScopeInstance;
    ExecutionEntity newParentExecution = ancestorActivityInstance.createAttachableExecution();
    Map<PvmActivity, PvmExecutionImpl> createdExecutions = newParentExecution.instantiateScopes((List) scopesToInstantiate, skipCustomListeners, skipIoMappings);
    for (ScopeImpl scope : scopesToInstantiate) {
        ExecutionEntity createdExecution = (ExecutionEntity) createdExecutions.get(scope);
        createdExecution.setActivity(null);
        createdExecution.setActive(false);
        executionBranch.visited(new MigratingActivityInstance(scope, createdExecution));
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 20 with PvmActivity

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

the class ActivityBehaviorUtil method getActivityBehavior.

public static ActivityBehavior getActivityBehavior(PvmExecutionImpl execution) {
    String id = execution.getId();
    PvmActivity activity = execution.getActivity();
    ensureNotNull(PvmException.class, "Execution '" + id + "' has no current activity.", "activity", activity);
    ActivityBehavior behavior = activity.getActivityBehavior();
    ensureNotNull(PvmException.class, "There is no behavior specified in " + activity + " for execution '" + id + "'.", "behavior", behavior);
    return behavior;
}
Also used : ActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior) CmmnActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.CmmnActivityBehavior) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Aggregations

PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)39 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)13 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)9 PvmTransition (org.camunda.bpm.engine.impl.pvm.PvmTransition)7 ActivityExecution (org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution)6 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)6 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 TransitionImpl (org.camunda.bpm.engine.impl.pvm.process.TransitionImpl)4 ReferenceWalker (org.camunda.bpm.engine.impl.tree.ReferenceWalker)4 ArrayList (java.util.ArrayList)3 PvmScope (org.camunda.bpm.engine.impl.pvm.PvmScope)3 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)3 CompositeActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior)3 List (java.util.List)2 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)2 ProcessDefinitionImpl (org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl)2 ExecutionStartContext (org.camunda.bpm.engine.impl.pvm.runtime.ExecutionStartContext)2 ActivityExecutionHierarchyWalker (org.camunda.bpm.engine.impl.tree.ActivityExecutionHierarchyWalker)2 ActivityExecutionMappingCollector (org.camunda.bpm.engine.impl.tree.ActivityExecutionMappingCollector)2 ActivityExecutionTuple (org.camunda.bpm.engine.impl.tree.ActivityExecutionTuple)2