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);
}
}
}
}
}
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;
}
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;
}
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);
}
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;
}
Aggregations