Search in sources :

Example 1 with ActivityExecution

use of org.activiti.engine.impl.pvm.delegate.ActivityExecution in project Activiti by Activiti.

the class ErrorPropagation method executeCatch.

private static void executeCatch(String errorHandlerId, ActivityExecution execution, String errorCode) {
    ProcessDefinitionImpl processDefinition = ((ExecutionEntity) execution).getProcessDefinition();
    ActivityImpl errorHandler = processDefinition.findActivity(errorHandlerId);
    if (errorHandler == null) {
        throw new ActivitiException(errorHandlerId + " not found in process definition");
    }
    boolean matchingParentFound = false;
    ActivityExecution leavingExecution = execution;
    ActivityImpl currentActivity = (ActivityImpl) execution.getActivity();
    ScopeImpl catchingScope = errorHandler.getParent();
    if (catchingScope instanceof ActivityImpl) {
        ActivityImpl catchingScopeActivity = (ActivityImpl) catchingScope;
        if (!catchingScopeActivity.isScope()) {
            // event subprocesses
            catchingScope = catchingScopeActivity.getParent();
        }
    }
    if (catchingScope instanceof PvmProcessDefinition) {
        executeEventHandler(errorHandler, ((ExecutionEntity) execution).getProcessInstance(), errorCode);
    } else {
        if (currentActivity.getId().equals(catchingScope.getId())) {
            matchingParentFound = true;
        } else {
            currentActivity = (ActivityImpl) currentActivity.getParent();
            // and matches the activity the boundary event is defined on
            while (!matchingParentFound && leavingExecution != null && currentActivity != null) {
                if (!leavingExecution.isConcurrent() && currentActivity.getId().equals(catchingScope.getId())) {
                    matchingParentFound = true;
                } else if (leavingExecution.isConcurrent()) {
                    leavingExecution = leavingExecution.getParent();
                } else {
                    currentActivity = currentActivity.getParentActivity();
                    leavingExecution = leavingExecution.getParent();
                }
            }
            // Follow parents up until matching scope can't be found anymore (needed to support for multi-instance)
            while (leavingExecution != null && leavingExecution.getParent() != null && leavingExecution.getParent().getActivity() != null && leavingExecution.getParent().getActivity().getId().equals(catchingScope.getId())) {
                leavingExecution = leavingExecution.getParent();
            }
        }
        if (matchingParentFound && leavingExecution != null) {
            executeEventHandler(errorHandler, leavingExecution, errorCode);
        } else {
            throw new ActivitiException("No matching parent execution for activity " + errorHandlerId + " found");
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl)

Example 2 with ActivityExecution

use of org.activiti.engine.impl.pvm.delegate.ActivityExecution in project Activiti by Activiti.

the class ExecutionEntity method findInactiveConcurrentExecutions.

public List<ActivityExecution> findInactiveConcurrentExecutions(PvmActivity activity) {
    List<ActivityExecution> inactiveConcurrentExecutionsInActivity = new ArrayList<ActivityExecution>();
    List<ActivityExecution> otherConcurrentExecutions = new ArrayList<ActivityExecution>();
    if (isConcurrent()) {
        List<? extends ActivityExecution> concurrentExecutions = getParent().getAllChildExecutions();
        for (ActivityExecution concurrentExecution : concurrentExecutions) {
            if (concurrentExecution.getActivity() != null && concurrentExecution.getActivity().getId().equals(activity.getId())) {
                if (!concurrentExecution.isActive()) {
                    inactiveConcurrentExecutionsInActivity.add(concurrentExecution);
                }
            } else {
                otherConcurrentExecutions.add(concurrentExecution);
            }
        }
    } else {
        if (!isActive()) {
            inactiveConcurrentExecutionsInActivity.add(this);
        } else {
            otherConcurrentExecutions.add(this);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("inactive concurrent executions in '{}': {}", activity, inactiveConcurrentExecutionsInActivity);
        log.debug("other concurrent executions: {}", otherConcurrentExecutions);
    }
    return inactiveConcurrentExecutionsInActivity;
}
Also used : ArrayList(java.util.ArrayList) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution)

Example 3 with ActivityExecution

use of org.activiti.engine.impl.pvm.delegate.ActivityExecution in project Activiti by Activiti.

the class EmbeddedSubProcess method timerFires.

// used by timers
@SuppressWarnings("unchecked")
public void timerFires(ActivityExecution execution, String signalName, Object signalData) throws Exception {
    PvmActivity timerActivity = execution.getActivity();
    boolean isInterrupting = (Boolean) timerActivity.getProperty("isInterrupting");
    List<ActivityExecution> recyclableExecutions;
    if (isInterrupting) {
        recyclableExecutions = removeAllExecutions(execution);
    } else {
        recyclableExecutions = Collections.EMPTY_LIST;
    }
    execution.takeAll(timerActivity.getOutgoingTransitions(), recyclableExecutions);
}
Also used : ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) PvmActivity(org.activiti.engine.impl.pvm.PvmActivity)

Example 4 with ActivityExecution

use of org.activiti.engine.impl.pvm.delegate.ActivityExecution in project Activiti by Activiti.

the class ParallelGateway method execute.

public void execute(ActivityExecution execution) {
    PvmActivity activity = execution.getActivity();
    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    execution.inactivate();
    List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
    int nbrOfExecutionsToJoin = execution.getActivity().getIncomingTransitions().size();
    int nbrOfExecutionsJoined = joinedExecutions.size();
    if (nbrOfExecutionsJoined == nbrOfExecutionsToJoin) {
        log.debug("parallel gateway '{}' activates: {} of {} joined", activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
        execution.takeAll(outgoingTransitions, joinedExecutions);
    } else if (log.isDebugEnabled()) {
        log.debug("parallel gateway '{}' does not activate: {} of {} joined", activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
    }
}
Also used : ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) PvmActivity(org.activiti.engine.impl.pvm.PvmActivity) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 5 with ActivityExecution

use of org.activiti.engine.impl.pvm.delegate.ActivityExecution in project Activiti by Activiti.

the class TerminateEndEventActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    ActivityImpl terminateEndEventActivity = (ActivityImpl) execution.getActivity();
    if (terminateAll) {
        ActivityExecution processInstanceExecution = findRootProcessInstanceExecution((ExecutionEntity) execution);
        terminateProcessInstanceExecution(execution, terminateEndEventActivity, processInstanceExecution);
    } else {
        ActivityExecution scopeExecution = ScopeUtil.findScopeExecution(execution);
        if (scopeExecution != null) {
            terminateExecution(execution, terminateEndEventActivity, scopeExecution);
        }
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution)

Aggregations

ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)23 ArrayList (java.util.ArrayList)8 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)8 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)7 PvmActivity (org.activiti.engine.impl.pvm.PvmActivity)6 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)6 InterpretableExecution (org.activiti.engine.impl.pvm.runtime.InterpretableExecution)4 List (java.util.List)3 ActivitiException (org.activiti.engine.ActivitiException)3 PvmException (org.activiti.engine.impl.pvm.PvmException)3 HashSet (java.util.HashSet)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 Expression (org.activiti.engine.delegate.Expression)1 Condition (org.activiti.engine.impl.Condition)1 PvmProcessDefinition (org.activiti.engine.impl.pvm.PvmProcessDefinition)1 ActivityBehavior (org.activiti.engine.impl.pvm.delegate.ActivityBehavior)1 CompositeActivityBehavior (org.activiti.engine.impl.pvm.delegate.CompositeActivityBehavior)1 ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)1 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)1 OutgoingExecution (org.activiti.engine.impl.pvm.runtime.OutgoingExecution)1