Search in sources :

Example 1 with CompositeActivityBehavior

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);
        }
    }
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with CompositeActivityBehavior

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);
        }
    }
}
Also used : PvmScope(org.camunda.bpm.engine.impl.pvm.PvmScope) PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) ActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with CompositeActivityBehavior

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;
}
Also used : CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) CancelBoundaryEventActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.CancelBoundaryEventActivityBehavior) SubProcessActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.SubProcessActivityBehavior) MultiInstanceActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior) ReceiveTaskActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.ReceiveTaskActivityBehavior) CompensationEventActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.CompensationEventActivityBehavior) EventSubProcessActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.EventSubProcessActivityBehavior) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) SequentialMultiInstanceActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.SequentialMultiInstanceActivityBehavior) ActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior) CancelEndEventActivityBehavior(org.camunda.bpm.engine.impl.bpmn.behavior.CancelEndEventActivityBehavior) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 4 with CompositeActivityBehavior

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;
}
Also used : PvmExecutionImpl(org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl) CompositeActivityBehavior(org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Aggregations

CompositeActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.CompositeActivityBehavior)4 PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 ActivityBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ActivityBehavior)2 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)2 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)2 CancelBoundaryEventActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.CancelBoundaryEventActivityBehavior)1 CancelEndEventActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.CancelEndEventActivityBehavior)1 CompensationEventActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.CompensationEventActivityBehavior)1 EventSubProcessActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.EventSubProcessActivityBehavior)1 MultiInstanceActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior)1 ReceiveTaskActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.ReceiveTaskActivityBehavior)1 SequentialMultiInstanceActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.SequentialMultiInstanceActivityBehavior)1 SubProcessActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.SubProcessActivityBehavior)1 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)1 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)1 PvmScope (org.camunda.bpm.engine.impl.pvm.PvmScope)1 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)1