Search in sources :

Example 6 with InterpretableExecution

use of org.activiti.engine.impl.pvm.runtime.InterpretableExecution in project Activiti by Activiti.

the class ExecutionEntity method removeEventScopes.

private void removeEventScopes() {
    List<InterpretableExecution> childExecutions = new ArrayList<InterpretableExecution>(getExecutions());
    for (InterpretableExecution childExecution : childExecutions) {
        if (childExecution.isEventScope()) {
            log.debug("removing eventScope {}", childExecution);
            childExecution.destroy();
            childExecution.remove();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) InterpretableExecution(org.activiti.engine.impl.pvm.runtime.InterpretableExecution)

Example 7 with InterpretableExecution

use of org.activiti.engine.impl.pvm.runtime.InterpretableExecution in project Activiti by Activiti.

the class BpmnActivityBehavior method performOutgoingBehavior.

/**
   * Actual implementation of leaving an activity.
   * 
   * @param execution
   *          The current execution context
   * @param checkConditions
   *          Whether or not to check conditions before determining whether or
   *          not to take a transition.
   * @param throwExceptionIfExecutionStuck
   *          If true, an {@link ActivitiException} will be thrown in case no
   *          transition could be found to leave the activity.
   */
protected void performOutgoingBehavior(ActivityExecution execution, boolean checkConditions, boolean throwExceptionIfExecutionStuck, List<ActivityExecution> reusableExecutions) {
    if (log.isDebugEnabled()) {
        log.debug("Leaving activity '{}'", execution.getActivity().getId());
    }
    String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
    List<PvmTransition> transitionsToTake = new ArrayList<PvmTransition>();
    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    for (PvmTransition outgoingTransition : outgoingTransitions) {
        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 || !checkConditions || condition.evaluate(outgoingTransition.getId(), execution)) {
                    transitionsToTake.add(outgoingTransition);
                }
            }
        } else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
            transitionsToTake.add(outgoingTransition);
        }
    }
    if (transitionsToTake.size() == 1) {
        execution.take(transitionsToTake.get(0));
    } else if (transitionsToTake.size() >= 1) {
        execution.inactivate();
        if (reusableExecutions == null || reusableExecutions.isEmpty()) {
            execution.takeAll(transitionsToTake, Arrays.asList(execution));
        } else {
            execution.takeAll(transitionsToTake, reusableExecutions);
        }
    } else {
        if (defaultSequenceFlow != null) {
            PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
            if (defaultTransition != null) {
                execution.take(defaultTransition);
            } else {
                throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' could not be not found");
            }
        } else {
            Object isForCompensation = execution.getActivity().getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION);
            if (isForCompensation != null && (Boolean) isForCompensation) {
                if (execution instanceof ExecutionEntity) {
                    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution);
                }
                InterpretableExecution parentExecution = (InterpretableExecution) execution.getParent();
                ((InterpretableExecution) execution).remove();
                parentExecution.signal("compensationDone", null);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("No outgoing sequence flow found for {}. Ending execution.", execution.getActivity().getId());
                }
                execution.end();
                if (throwExceptionIfExecutionStuck) {
                    throw new ActivitiException("No outgoing sequence flow of the inclusive gateway '" + execution.getActivity().getId() + "' could be selected for continuing the process");
                }
            }
        }
    }
}
Also used : Condition(org.activiti.engine.impl.Condition) ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Expression(org.activiti.engine.delegate.Expression) ArrayList(java.util.ArrayList) InterpretableExecution(org.activiti.engine.impl.pvm.runtime.InterpretableExecution) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Example 8 with InterpretableExecution

use of org.activiti.engine.impl.pvm.runtime.InterpretableExecution in project Activiti by Activiti.

the class ErrorPropagation method executeEventHandler.

private static void executeEventHandler(ActivityImpl borderEventActivity, ActivityExecution leavingExecution, String errorCode) {
    if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createErrorEvent(ActivitiEventType.ACTIVITY_ERROR_RECEIVED, borderEventActivity.getId(), errorCode, leavingExecution.getId(), leavingExecution.getProcessInstanceId(), leavingExecution.getProcessDefinitionId()));
    }
    // The current activity of the execution will be changed in the next lines.
    // So we must make sure the activity is ended correctly here
    // The other executions (for example when doing something parallel in a subprocess, will
    // be destroyed by the destroy scope operation (but this execution will be used to do it and 
    // will have list the original activity by then)
    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) leavingExecution);
    if (borderEventActivity.getActivityBehavior() instanceof EventSubProcessStartEventActivityBehavior) {
        InterpretableExecution execution = (InterpretableExecution) leavingExecution;
        execution.setActivity(borderEventActivity.getParentActivity());
        // make sure the listeners are invoked!
        execution.performOperation(AtomicOperation.ACTIVITY_START);
    } else {
        leavingExecution.executeActivity(borderEventActivity);
    }
}
Also used : EventSubProcessStartEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.EventSubProcessStartEventActivityBehavior) InterpretableExecution(org.activiti.engine.impl.pvm.runtime.InterpretableExecution)

Example 9 with InterpretableExecution

use of org.activiti.engine.impl.pvm.runtime.InterpretableExecution in project Activiti by Activiti.

the class EventScopeCreatingSubprocess method lastExecutionEnded.

/*
   * Incoming execution is transformed into an event scope, 
   * new, non-concurrent execution leaves activity 
   */
@SuppressWarnings("unchecked")
public void lastExecutionEnded(ActivityExecution execution) {
    ActivityExecution outgoingExecution = execution.getParent().createExecution();
    outgoingExecution.setConcurrent(false);
    ((InterpretableExecution) outgoingExecution).setActivity((ActivityImpl) execution.getActivity());
    // eventscope execution
    execution.setConcurrent(false);
    execution.setActive(false);
    ((InterpretableExecution) execution).setEventScope(true);
    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    if (outgoingTransitions.isEmpty()) {
        outgoingExecution.end();
    } else {
        outgoingExecution.takeAll(outgoingTransitions, Collections.EMPTY_LIST);
    }
}
Also used : ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) InterpretableExecution(org.activiti.engine.impl.pvm.runtime.InterpretableExecution) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition)

Aggregations

InterpretableExecution (org.activiti.engine.impl.pvm.runtime.InterpretableExecution)9 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)4 ArrayList (java.util.ArrayList)3 ActivitiException (org.activiti.engine.ActivitiException)3 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)2 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)2 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)2 Expression (org.activiti.engine.delegate.Expression)1 Condition (org.activiti.engine.impl.Condition)1 EventSubProcessStartEventActivityBehavior (org.activiti.engine.impl.bpmn.behavior.EventSubProcessStartEventActivityBehavior)1 HistoryManager (org.activiti.engine.impl.history.HistoryManager)1