Search in sources :

Example 31 with ScopeImpl

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

the class LegacyBehavior method removeLegacyNonScopesFromMapping.

/**
 * Remove all entries for legacy non-scopes given that the assigned scope execution is also responsible for another scope
 */
public static void removeLegacyNonScopesFromMapping(Map<ScopeImpl, PvmExecutionImpl> mapping) {
    Map<PvmExecutionImpl, List<ScopeImpl>> scopesForExecutions = new HashMap<PvmExecutionImpl, List<ScopeImpl>>();
    for (Map.Entry<ScopeImpl, PvmExecutionImpl> mappingEntry : mapping.entrySet()) {
        List<ScopeImpl> scopesForExecution = scopesForExecutions.get(mappingEntry.getValue());
        if (scopesForExecution == null) {
            scopesForExecution = new ArrayList<ScopeImpl>();
            scopesForExecutions.put(mappingEntry.getValue(), scopesForExecution);
        }
        scopesForExecution.add(mappingEntry.getKey());
    }
    for (Map.Entry<PvmExecutionImpl, List<ScopeImpl>> scopesForExecution : scopesForExecutions.entrySet()) {
        List<ScopeImpl> scopes = scopesForExecution.getValue();
        if (scopes.size() > 1) {
            ScopeImpl topMostScope = getTopMostScope(scopes);
            for (ScopeImpl scope : scopes) {
                if (scope != scope.getProcessDefinition() && scope != topMostScope) {
                    mapping.remove(scope);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with ScopeImpl

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

the class LegacyBehavior method createActivityExecutionMapping.

/**
 * Creates an activity execution mapping, when the scope hierarchy and the execution hierarchy are out of sync.
 *
 * @param scopeExecutions
 * @param scopes
 * @return
 */
public static Map<ScopeImpl, PvmExecutionImpl> createActivityExecutionMapping(List<PvmExecutionImpl> scopeExecutions, List<ScopeImpl> scopes) {
    PvmExecutionImpl deepestExecution = scopeExecutions.get(0);
    if (isLegacyAsyncAtMultiInstance(deepestExecution)) {
        // in case the deepest execution is in fact async at multi-instance, the multi instance body is part
        // of the list of scopes, however it is not instantiated yet or has already ended. Thus it must be removed.
        scopes.remove(0);
    }
    // The trees are out of sync.
    // We are missing executions:
    int numOfMissingExecutions = scopes.size() - scopeExecutions.size();
    // We need to find out which executions are missing.
    // Consider: elements which did not use to be scopes are now scopes.
    // But, this does not mean that all instances of elements which became scopes
    // are missing their executions. We could have created new instances in the
    // lower part of the tree after legacy behavior was turned off while instances of these elements
    // further up the hierarchy miss scopes. So we need to iterate from the top down and skip all scopes which
    // were not scopes before:
    Collections.reverse(scopeExecutions);
    Collections.reverse(scopes);
    Map<ScopeImpl, PvmExecutionImpl> mapping = new HashMap<ScopeImpl, PvmExecutionImpl>();
    // process definition / process instance.
    mapping.put(scopes.get(0), scopeExecutions.get(0));
    // nested activities
    int executionCounter = 0;
    for (int i = 1; i < scopes.size(); i++) {
        ActivityImpl scope = (ActivityImpl) scopes.get(i);
        PvmExecutionImpl scopeExecutionCandidate = null;
        if (executionCounter + 1 < scopeExecutions.size()) {
            scopeExecutionCandidate = scopeExecutions.get(executionCounter + 1);
        }
        if (numOfMissingExecutions > 0 && wasNoScope(scope, scopeExecutionCandidate)) {
            // found a missing scope
            numOfMissingExecutions--;
        } else {
            executionCounter++;
        }
        if (executionCounter >= scopeExecutions.size()) {
            throw new ProcessEngineException("Cannot construct activity-execution mapping: there are " + "more scope executions missing than explained by the flow scope hierarchy.");
        }
        PvmExecutionImpl execution = scopeExecutions.get(executionCounter);
        mapping.put(scope, execution);
    }
    return mapping;
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) HashMap(java.util.HashMap) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 33 with ScopeImpl

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

the class ProcessInstanceStartContext method getInstantiationStack.

@SuppressWarnings({ "unchecked", "rawtypes" })
public InstantiationStack getInstantiationStack() {
    if (instantiationStack == null) {
        FlowScopeWalker flowScopeWalker = new FlowScopeWalker(initial.getFlowScope());
        ScopeCollector scopeCollector = new ScopeCollector();
        flowScopeWalker.addPreVisitor(scopeCollector).walkWhile(new ReferenceWalker.WalkCondition<ScopeImpl>() {

            public boolean isFulfilled(ScopeImpl element) {
                return element == null || element == initial.getProcessDefinition();
            }
        });
        List<PvmActivity> scopeActivities = (List) scopeCollector.getScopes();
        Collections.reverse(scopeActivities);
        instantiationStack = new InstantiationStack(scopeActivities, initial, null);
    }
    return instantiationStack;
}
Also used : ScopeCollector(org.camunda.bpm.engine.impl.tree.ScopeCollector) ReferenceWalker(org.camunda.bpm.engine.impl.tree.ReferenceWalker) FlowScopeWalker(org.camunda.bpm.engine.impl.tree.FlowScopeWalker) List(java.util.List) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 34 with ScopeImpl

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

the class FoxAtomicOperationDeleteCascadeFireActivityEnd method execute.

@Override
public void execute(PvmExecutionImpl execution) {
    ScopeImpl scope = getScope(execution);
    int executionListenerIndex = execution.getListenerIndex();
    List<DelegateListener<? extends BaseDelegateExecution>> executionListeners = scope.getListeners(getEventName());
    for (DelegateListener<? extends BaseDelegateExecution> listener : executionListeners) {
        execution.setEventName(getEventName());
        execution.setEventSource(scope);
        try {
            execution.invokeListener(listener);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new PvmException("couldn't execute event listener : " + e.getMessage(), e);
        }
        executionListenerIndex += 1;
        execution.setListenerIndex(executionListenerIndex);
    }
    execution.setListenerIndex(0);
    execution.setEventName(null);
    execution.setEventSource(null);
    eventNotificationsCompleted(execution);
}
Also used : BaseDelegateExecution(org.camunda.bpm.engine.delegate.BaseDelegateExecution) DelegateListener(org.camunda.bpm.engine.delegate.DelegateListener) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmException(org.camunda.bpm.engine.impl.pvm.PvmException) PvmException(org.camunda.bpm.engine.impl.pvm.PvmException)

Example 35 with ScopeImpl

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

the class PvmAtomicOperationDeleteCascadeFireActivityEnd method getFlowScopeActivity.

protected ActivityImpl getFlowScopeActivity(PvmActivity activity) {
    ScopeImpl flowScope = activity.getFlowScope();
    ActivityImpl flowScopeActivity = null;
    if (flowScope.getProcessDefinition() != flowScope) {
        flowScopeActivity = (ActivityImpl) flowScope;
    }
    return flowScopeActivity;
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)

Aggregations

ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)37 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)10 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)10 PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)6 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)6 FlowScopeWalker (org.camunda.bpm.engine.impl.tree.FlowScopeWalker)5 HashMap (java.util.HashMap)4 List (java.util.List)4 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 ReferenceWalker (org.camunda.bpm.engine.impl.tree.ReferenceWalker)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 PvmScope (org.camunda.bpm.engine.impl.pvm.PvmScope)3 Deployment (org.camunda.bpm.engine.test.Deployment)3 MigratingActivityInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance)2 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)2 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)2 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)2 CompositeActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior)2