Search in sources :

Example 16 with ActivityExecution

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

the class TerminateEndEventActivityBehavior method dispatchExecutionCancelled.

private void dispatchExecutionCancelled(ActivityExecution execution, ActivityImpl causeActivity) {
    // subprocesses
    for (ActivityExecution subExecution : execution.getExecutions()) {
        dispatchExecutionCancelled(subExecution, causeActivity);
    }
    // call activities
    ExecutionEntity subProcessInstance = Context.getCommandContext().getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId());
    if (subProcessInstance != null) {
        dispatchExecutionCancelled(subProcessInstance, causeActivity);
    }
    // activity with message/signal boundary events
    ActivityImpl activity = (ActivityImpl) execution.getActivity();
    if (activity != null && activity.getActivityBehavior() != null && activity != causeActivity) {
        dispatchActivityCancelled(execution, activity, causeActivity);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution)

Example 17 with ActivityExecution

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

the class ParallelMultiInstanceBehavior method createInstances.

/**
   * Handles the parallel case of spawning the instances.
   * Will create child executions accordingly for every instance needed.
   */
protected void createInstances(ActivityExecution execution) throws Exception {
    int nrOfInstances = resolveNrOfInstances(execution);
    if (nrOfInstances < 0) {
        throw new ActivitiIllegalArgumentException("Invalid number of instances: must be non-negative integer value" + ", but was " + nrOfInstances);
    }
    setLoopVariable(execution, NUMBER_OF_INSTANCES, nrOfInstances);
    setLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES, 0);
    setLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES, nrOfInstances);
    List<ActivityExecution> concurrentExecutions = new ArrayList<ActivityExecution>();
    for (int loopCounter = 0; loopCounter < nrOfInstances; loopCounter++) {
        ActivityExecution concurrentExecution = execution.createExecution();
        concurrentExecution.setActive(true);
        concurrentExecution.setConcurrent(true);
        concurrentExecution.setScope(false);
        // without any differentiation to which embedded subprocess they belong
        if (isExtraScopeNeeded()) {
            ActivityExecution extraScopedExecution = concurrentExecution.createExecution();
            extraScopedExecution.setActive(true);
            extraScopedExecution.setConcurrent(false);
            extraScopedExecution.setScope(true);
            concurrentExecution = extraScopedExecution;
        }
        concurrentExecutions.add(concurrentExecution);
        logLoopDetails(concurrentExecution, "initialized", loopCounter, 0, nrOfInstances, nrOfInstances);
    }
    // due to possible child execution pruning.
    for (int loopCounter = 0; loopCounter < nrOfInstances; loopCounter++) {
        ActivityExecution concurrentExecution = concurrentExecutions.get(loopCounter);
        // and completionCondition has been met in the meantime
        if (concurrentExecution.isActive() && !concurrentExecution.isEnded() && concurrentExecution.getParent().isActive() && !concurrentExecution.getParent().isEnded()) {
            setLoopVariable(concurrentExecution, getCollectionElementIndexVariable(), loopCounter);
            executeOriginalBehavior(concurrentExecution, loopCounter);
        }
    }
    // have been a better solution), as it would break boundary event behavior.
    if (!concurrentExecutions.isEmpty()) {
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
        executionEntity.setActive(false);
    }
}
Also used : ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution)

Example 18 with ActivityExecution

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

the class InclusiveGatewayActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    execution.inactivate();
    lockConcurrentRoot(execution);
    PvmActivity activity = execution.getActivity();
    if (!activeConcurrentExecutionsExist(execution)) {
        if (log.isDebugEnabled()) {
            log.debug("inclusive gateway '{}' activates", activity.getId());
        }
        List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
        String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
        List<PvmTransition> transitionsToTake = new ArrayList<PvmTransition>();
        for (PvmTransition outgoingTransition : execution.getActivity().getOutgoingTransitions()) {
            Expression skipExpression = outgoingTransition.getSkipExpression();
            if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression)) {
                if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
                    Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
                    if (condition == null || condition.evaluate(outgoingTransition.getId(), execution)) {
                        transitionsToTake.add(outgoingTransition);
                    }
                }
            } else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
                transitionsToTake.add(outgoingTransition);
            }
        }
        if (!transitionsToTake.isEmpty()) {
            execution.takeAll(transitionsToTake, joinedExecutions);
        } else {
            if (defaultSequenceFlow != null) {
                PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
                if (defaultTransition != null) {
                    transitionsToTake.add(defaultTransition);
                    execution.takeAll(transitionsToTake, joinedExecutions);
                } else {
                    throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' could not be not found");
                }
            } else {
                // No sequence flow could be found, not even a default one
                throw new ActivitiException("No outgoing sequence flow of the inclusive gateway '" + execution.getActivity().getId() + "' could be selected for continuing the process");
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Inclusive gateway '{}' does not activate", activity.getId());
        }
    }
}
Also used : Condition(org.activiti.engine.impl.Condition) ActivitiException(org.activiti.engine.ActivitiException) Expression(org.activiti.engine.delegate.Expression) ArrayList(java.util.ArrayList) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) PvmActivity(org.activiti.engine.impl.pvm.PvmActivity) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 19 with ActivityExecution

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

the class ExecutionImpl method takeAll.

@SuppressWarnings("unchecked")
public void takeAll(List<PvmTransition> transitions, List<ActivityExecution> recyclableExecutions) {
    transitions = new ArrayList<PvmTransition>(transitions);
    recyclableExecutions = (recyclableExecutions != null ? new ArrayList<ActivityExecution>(recyclableExecutions) : new ArrayList<ActivityExecution>());
    if (recyclableExecutions.size() > 1) {
        for (ActivityExecution recyclableExecution : recyclableExecutions) {
            if (((ExecutionImpl) recyclableExecution).isScope()) {
                throw new PvmException("joining scope executions is not allowed");
            }
        }
    }
    ExecutionImpl concurrentRoot = ((isConcurrent && !isScope) ? getParent() : this);
    List<ExecutionImpl> concurrentActiveExecutions = new ArrayList<ExecutionImpl>();
    for (ExecutionImpl execution : concurrentRoot.getExecutions()) {
        if (execution.isActive()) {
            concurrentActiveExecutions.add(execution);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("transitions to take concurrent: {}", transitions);
        log.debug("active concurrent executions: {}", concurrentActiveExecutions);
    }
    if ((transitions.size() == 1) && (concurrentActiveExecutions.isEmpty())) {
        @SuppressWarnings("rawtypes") List<ExecutionImpl> recyclableExecutionImpls = (List) recyclableExecutions;
        for (ExecutionImpl prunedExecution : recyclableExecutionImpls) {
            // Others are already ended (end activities)
            if (!prunedExecution.isEnded()) {
                log.debug("pruning execution {}", prunedExecution);
                prunedExecution.remove();
            }
        }
        log.debug("activating the concurrent root {} as the single path of execution going forward", concurrentRoot);
        concurrentRoot.setActive(true);
        concurrentRoot.setActivity(activity);
        concurrentRoot.setConcurrent(false);
        concurrentRoot.take(transitions.get(0));
    } else {
        List<OutgoingExecution> outgoingExecutions = new ArrayList<OutgoingExecution>();
        recyclableExecutions.remove(concurrentRoot);
        log.debug("recyclable executions for reused: {}", recyclableExecutions);
        // first create the concurrent executions
        while (!transitions.isEmpty()) {
            PvmTransition outgoingTransition = transitions.remove(0);
            ExecutionImpl outgoingExecution = null;
            if (recyclableExecutions.isEmpty()) {
                outgoingExecution = concurrentRoot.createExecution();
                log.debug("new {} created to take transition {}", outgoingExecution, outgoingTransition);
            } else {
                outgoingExecution = (ExecutionImpl) recyclableExecutions.remove(0);
                log.debug("recycled {} to take transition {}", outgoingExecution, outgoingTransition);
            }
            outgoingExecution.setActive(true);
            outgoingExecution.setScope(false);
            outgoingExecution.setConcurrent(true);
            outgoingExecutions.add(new OutgoingExecution(outgoingExecution, outgoingTransition, true));
        }
        // prune the executions that are not recycled 
        for (ActivityExecution prunedExecution : recyclableExecutions) {
            log.debug("pruning execution {}", prunedExecution);
            prunedExecution.end();
        }
        // then launch all the concurrent executions
        for (OutgoingExecution outgoingExecution : outgoingExecutions) {
            outgoingExecution.take();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) PvmException(org.activiti.engine.impl.pvm.PvmException)

Example 20 with ActivityExecution

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

the class ExecutionImpl 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().getExecutions();
        for (ActivityExecution concurrentExecution : concurrentExecutions) {
            if (concurrentExecution.getActivity() != null && concurrentExecution.getActivity().getId().equals(activity.getId())) {
                if (concurrentExecution.isActive()) {
                    throw new PvmException("didn't expect active execution in " + activity + ". bug?");
                }
                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) PvmException(org.activiti.engine.impl.pvm.PvmException)

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