use of org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior in project camunda-bpm-platform by camunda.
the class CompensationEventHandler method handleEvent.
@Override
public void handleEvent(EventSubscriptionEntity eventSubscription, Object payload, String businessKey, CommandContext commandContext) {
eventSubscription.delete();
String configuration = eventSubscription.getConfiguration();
ensureNotNull("Compensating execution not set for compensate event subscription with id " + eventSubscription.getId(), "configuration", configuration);
ExecutionEntity compensatingExecution = commandContext.getExecutionManager().findExecutionById(configuration);
ActivityImpl compensationHandler = eventSubscription.getActivity();
// activate execution
compensatingExecution.setActive(true);
if (compensatingExecution.getActivity().getActivityBehavior() instanceof CompositeActivityBehavior) {
compensatingExecution.getParent().setActivityInstanceId(compensatingExecution.getActivityInstanceId());
}
if (compensationHandler.isScope() && !compensationHandler.isCompensationHandler()) {
// descend into scope:
List<EventSubscriptionEntity> eventsForThisScope = compensatingExecution.getCompensateEventSubscriptions();
CompensationUtil.throwCompensationEvent(eventsForThisScope, compensatingExecution, false);
} else {
try {
if (compensationHandler.isSubProcessScope() && compensationHandler.isTriggeredByEvent()) {
compensatingExecution.executeActivity(compensationHandler);
} else {
// since we already have a scope execution, we don't need to create another one
// for a simple scoped compensation handler
compensatingExecution.setActivity(compensationHandler);
compensatingExecution.performOperation(PvmAtomicOperation.ACTIVITY_START);
}
} catch (Exception e) {
throw new ProcessEngineException("Error while handling compensation event " + eventSubscription, e);
}
}
}
use of org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior in project camunda-bpm-platform by camunda.
the class PvmAtomicOperationActivityEnd method execute.
public void execute(PvmExecutionImpl execution) {
// restore activity instance id
if (execution.getActivityInstanceId() == null) {
execution.setActivityInstanceId(execution.getParentActivityInstanceId());
}
PvmActivity activity = execution.getActivity();
Map<ScopeImpl, PvmExecutionImpl> activityExecutionMapping = execution.createActivityExecutionMapping();
PvmExecutionImpl propagatingExecution = execution;
if (execution.isScope() && activity.isScope()) {
if (!LegacyBehavior.destroySecondNonScope(execution)) {
execution.destroy();
if (!execution.isConcurrent()) {
execution.remove();
propagatingExecution = execution.getParent();
propagatingExecution.setActivity(execution.getActivity());
}
}
}
propagatingExecution = LegacyBehavior.determinePropagatingExecutionOnEnd(propagatingExecution, activityExecutionMapping);
PvmScope flowScope = activity.getFlowScope();
// 1. flow scope = Process Definition
if (flowScope == activity.getProcessDefinition()) {
// 1.1 concurrent execution => end + tryPrune()
if (propagatingExecution.isConcurrent()) {
propagatingExecution.remove();
propagatingExecution.getParent().tryPruneLastConcurrentChild();
propagatingExecution.getParent().forceUpdate();
} else {
// 1.2 Process End
propagatingExecution.setEnded(true);
if (!propagatingExecution.isPreserveScope()) {
propagatingExecution.performOperation(PROCESS_END);
}
}
} else {
// 2. flowScope != process definition
PvmActivity flowScopeActivity = (PvmActivity) flowScope;
ActivityBehavior activityBehavior = flowScopeActivity.getActivityBehavior();
if (activityBehavior instanceof CompositeActivityBehavior) {
CompositeActivityBehavior compositeActivityBehavior = (CompositeActivityBehavior) activityBehavior;
// 2.1 Concurrent execution => composite behavior.concurrentExecutionEnded()
if (propagatingExecution.isConcurrent() && !LegacyBehavior.isConcurrentScope(propagatingExecution)) {
compositeActivityBehavior.concurrentChildExecutionEnded(propagatingExecution.getParent(), propagatingExecution);
} else {
// 2.2 Scope Execution => composite behavior.complete()
propagatingExecution.setActivity(flowScopeActivity);
compositeActivityBehavior.complete(propagatingExecution);
}
} else {
// activity behavior is not composite => this is unexpected
throw new ProcessEngineException("Expected behavior of composite scope " + activity + " to be a CompositeActivityBehavior but got " + activityBehavior);
}
}
}
use of org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior in project camunda-bpm-platform by camunda.
the class LegacyBehavior method eventSubprocessConcurrentChildExecutionEnded.
public static boolean eventSubprocessConcurrentChildExecutionEnded(ActivityExecution scopeExecution, ActivityExecution endedExecution) {
boolean performLegacyBehavior = isLegacyBehaviorRequired(endedExecution);
if (performLegacyBehavior) {
LOG.endConcurrentExecutionInEventSubprocess();
// notify the grandparent flow scope in a similar way PvmAtomicOperationAcitivtyEnd does
ScopeImpl flowScope = endedExecution.getActivity().getFlowScope();
if (flowScope != null) {
flowScope = flowScope.getFlowScope();
if (flowScope != null) {
if (flowScope == endedExecution.getActivity().getProcessDefinition()) {
endedExecution.remove();
scopeExecution.tryPruneLastConcurrentChild();
scopeExecution.forceUpdate();
} else {
PvmActivity flowScopeActivity = (PvmActivity) flowScope;
ActivityBehavior activityBehavior = flowScopeActivity.getActivityBehavior();
if (activityBehavior instanceof CompositeActivityBehavior) {
((CompositeActivityBehavior) activityBehavior).concurrentChildExecutionEnded(scopeExecution, endedExecution);
}
}
}
}
}
return performLegacyBehavior;
}
use of org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior in project camunda-bpm-platform by camunda.
the class PvmAtomicOperationActivityInstanceEnd method eventNotificationsStarted.
@Override
protected PvmExecutionImpl eventNotificationsStarted(PvmExecutionImpl execution) {
execution.incrementSequenceCounter();
// hack around execution tree structure not being in sync with activity instance concept:
// if we end a scope activity, take remembered activity instance from parent and set on
// execution before calling END listeners.
PvmExecutionImpl parent = execution.getParent();
PvmActivity activity = execution.getActivity();
if (parent != null && execution.isScope() && activity != null && activity.isScope() && (activity.getActivityBehavior() instanceof CompositeActivityBehavior || (CompensationBehavior.isCompensationThrowing(execution)) && !LegacyBehavior.isCompensationThrowing(execution))) {
LOG.debugLeavesActivityInstance(execution, execution.getActivityInstanceId());
// use remembered activity instance id from parent
execution.setActivityInstanceId(parent.getActivityInstanceId());
// make parent go one scope up.
parent.leaveActivityInstance();
}
return execution;
}
Aggregations