use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class AbstractInstanceCancellationCmd method execute.
public Void execute(CommandContext commandContext) {
ExecutionEntity sourceInstanceExecution = determineSourceInstanceExecution(commandContext);
// Outline:
// 1. find topmost scope execution beginning at scopeExecution that has exactly
// one child (this is the topmost scope we can cancel)
// 2. cancel all children of the topmost execution
// 3. cancel the activity of the topmost execution itself (if applicable)
// 4. remove topmost execution (and concurrent parent) if topmostExecution is not the process instance
ExecutionEntity topmostCancellableExecution = sourceInstanceExecution;
ExecutionEntity parentScopeExecution = (ExecutionEntity) topmostCancellableExecution.getParentScopeExecution(false);
// we have reached the correct execution
while (parentScopeExecution != null && (parentScopeExecution.getNonEventScopeExecutions().size() <= 1)) {
topmostCancellableExecution = parentScopeExecution;
parentScopeExecution = (ExecutionEntity) topmostCancellableExecution.getParentScopeExecution(false);
}
if (topmostCancellableExecution.isPreserveScope()) {
topmostCancellableExecution.interrupt(cancellationReason, skipCustomListeners, skipIoMappings);
topmostCancellableExecution.leaveActivityInstance();
topmostCancellableExecution.setActivity(null);
} else {
topmostCancellableExecution.deleteCascade(cancellationReason, skipCustomListeners, skipIoMappings);
handleChildRemovalInScope(topmostCancellableExecution);
}
return null;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class AbstractProcessInstanceModificationCommand method getScopeExecutionForActivityInstance.
protected ExecutionEntity getScopeExecutionForActivityInstance(ExecutionEntity processInstance, ActivityExecutionTreeMapping mapping, ActivityInstance activityInstance) {
ensureNotNull("activityInstance", activityInstance);
ProcessDefinitionImpl processDefinition = processInstance.getProcessDefinition();
ScopeImpl scope = getScopeForActivityInstance(processDefinition, activityInstance);
Set<ExecutionEntity> executions = mapping.getExecutions(scope);
Set<String> activityInstanceExecutions = new HashSet<String>(Arrays.asList(activityInstance.getExecutionIds()));
// remove with fix of CAM-3574
for (String activityInstanceExecutionId : activityInstance.getExecutionIds()) {
ExecutionEntity execution = Context.getCommandContext().getExecutionManager().findExecutionById(activityInstanceExecutionId);
if (execution.isConcurrent() && execution.hasChildren()) {
// concurrent executions have at most one child
ExecutionEntity child = execution.getExecutions().get(0);
activityInstanceExecutions.add(child.getId());
}
}
// find the scope execution for the given activity instance
Set<ExecutionEntity> retainedExecutionsForInstance = new HashSet<ExecutionEntity>();
for (ExecutionEntity execution : executions) {
if (activityInstanceExecutions.contains(execution.getId())) {
retainedExecutionsForInstance.add(execution);
}
}
if (retainedExecutionsForInstance.size() != 1) {
throw new ProcessEngineException("There are " + retainedExecutionsForInstance.size() + " (!= 1) executions for activity instance " + activityInstance.getId());
}
return retainedExecutionsForInstance.iterator().next();
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class CompensationUtil method createEventScopeExecution.
/**
* creates an event scope for the given execution:
*
* create a new event scope execution under the parent of the given execution
* and move all event subscriptions to that execution.
*
* this allows us to "remember" the event subscriptions after finishing a
* scope
*/
public static void createEventScopeExecution(ExecutionEntity execution) {
// parent execution is a subprocess or a miBody
ActivityImpl activity = execution.getActivity();
ExecutionEntity scopeExecution = (ExecutionEntity) execution.findExecutionForFlowScope(activity.getFlowScope());
List<EventSubscriptionEntity> eventSubscriptions = execution.getCompensateEventSubscriptions();
if (eventSubscriptions.size() > 0 || hasCompensationEventSubprocess(activity)) {
ExecutionEntity eventScopeExecution = scopeExecution.createExecution();
eventScopeExecution.setActivity(execution.getActivity());
eventScopeExecution.activityInstanceStarting();
eventScopeExecution.enterActivityInstance();
eventScopeExecution.setActive(false);
eventScopeExecution.setConcurrent(false);
eventScopeExecution.setEventScope(true);
// copy local variables to eventScopeExecution by value. This way,
// the eventScopeExecution references a 'snapshot' of the local variables
Map<String, Object> variables = execution.getVariablesLocal();
for (Entry<String, Object> variable : variables.entrySet()) {
eventScopeExecution.setVariableLocal(variable.getKey(), variable.getValue());
}
// set event subscriptions to the event scope execution:
for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
EventSubscriptionEntity newSubscription = EventSubscriptionEntity.createAndInsert(eventScopeExecution, EventType.COMPENSATE, eventSubscriptionEntity.getActivity());
newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration());
// use the original date
newSubscription.setCreated(eventSubscriptionEntity.getCreated());
}
// (ensuring they don't get removed when 'execution' gets removed)
for (PvmExecutionImpl childEventScopeExecution : execution.getEventScopeExecutions()) {
childEventScopeExecution.setParent(eventScopeExecution);
}
ActivityImpl compensationHandler = getEventScopeCompensationHandler(execution);
EventSubscriptionEntity eventSubscription = EventSubscriptionEntity.createAndInsert(scopeExecution, EventType.COMPENSATE, compensationHandler);
eventSubscription.setConfiguration(eventScopeExecution.getId());
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class CompensationUtil method throwCompensationEvent.
/**
* we create a separate execution for each compensation handler invocation.
*/
public static void throwCompensationEvent(List<EventSubscriptionEntity> eventSubscriptions, ActivityExecution execution, boolean async) {
// first spawn the compensating executions
for (EventSubscriptionEntity eventSubscription : eventSubscriptions) {
// check whether compensating execution is already created
// (which is the case when compensating an embedded subprocess,
// where the compensating execution is created when leaving the subprocess
// and holds snapshot data).
ExecutionEntity compensatingExecution = getCompensatingExecution(eventSubscription);
if (compensatingExecution != null) {
if (compensatingExecution.getParent() != execution) {
// move the compensating execution under this execution if this is not the case yet
compensatingExecution.setParent((PvmExecutionImpl) execution);
}
compensatingExecution.setEventScope(false);
} else {
compensatingExecution = (ExecutionEntity) execution.createExecution();
eventSubscription.setConfiguration(compensatingExecution.getId());
}
compensatingExecution.setConcurrent(true);
}
// signal compensation events in REVERSE order of their 'created' timestamp
Collections.sort(eventSubscriptions, new Comparator<EventSubscriptionEntity>() {
@Override
public int compare(EventSubscriptionEntity o1, EventSubscriptionEntity o2) {
return o2.getCreated().compareTo(o1.getCreated());
}
});
for (EventSubscriptionEntity compensateEventSubscriptionEntity : eventSubscriptions) {
compensateEventSubscriptionEntity.eventReceived(null, async);
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.
the class AbstractCorrelateMessageCmd method instantiateProcess.
protected ProcessInstance instantiateProcess(CommandContext commandContext, CorrelationHandlerResult correlationResult) {
ProcessDefinitionEntity processDefinitionEntity = correlationResult.getProcessDefinitionEntity();
ActivityImpl messageStartEvent = processDefinitionEntity.findActivity(correlationResult.getStartEventActivityId());
ExecutionEntity processInstance = processDefinitionEntity.createProcessInstance(builder.getBusinessKey(), messageStartEvent);
processInstance.start(builder.getPayloadProcessInstanceVariables());
return processInstance;
}
Aggregations