/* * If the current flow element is part of a compensation, we don't always * want to follow the regular rules of leaving an activity. * More specifically, if there are no outgoing sequenceflow, we simply must stop * the execution there and don't go up in the scopes as we usually do * to find the outgoing sequenceflow * 如果当前流程元素是补偿的一部分,我们并不总是希望遵循离开活动的常规规则。 * 更具体地说,如果没有传出序列流,我们只需在那里停止执行,而不是像我们通常做的那样在范围内找到传出序列流 */
cleanupCompensation(); return; }
// When leaving the current activity, we need to delete any related execution (eg active boundary events) // 当离开当前活动时,我们需要删除任何相关的执行(例如活动边界事件) cleanupExecutions(currentFlowElement);
logger.debug("Leaving flow node {} with id '{}' by following it's {} outgoing sequenceflow", flowNode.getClass(), flowNode.getId(), flowNode.getOutgoingFlows().size());
// Determine which sequence flows can be used for leaving 确定哪些序列流可用于离开 List<SequenceFlow> outgoingSequenceFlows = new ArrayList<SequenceFlow>(); //循环获取所有出线的表达式并计算 for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) { //获取跳过表达式 String skipExpressionString = sequenceFlow.getSkipExpression(); //_ACTIVITI_SKIP_EXPRESSION_ENABLED 全局变量是否开启跳过表达式 //未开启跳过表达式则计算 if (!SkipExpressionUtil.isSkipExpressionEnabled(execution,skipExpressionString)) { //忽略计算条件(false)或者(条件表达式计算为true且(默认出现为null或非默认出线) if (!evaluateConditions|| (evaluateConditions && ConditionUtil.hasTrueCondition(sequenceFlow, execution) && (defaultSequenceFlowId == null || !defaultSequenceFlowId.equals(sequenceFlow.getId())))) { outgoingSequenceFlows.add(sequenceFlow); } } elseif (flowNode.getOutgoingFlows().size() == 1 || SkipExpressionUtil.shouldSkipFlowElement(commandContext, execution, skipExpressionString)) { // The 'skip' for a sequence flow means that we skip the condition, not the sequence flow. //序列流的“跳过”意味着我们跳过条件,而不是序列流。 //出线为1或者计算应该跳过流元素 outgoingSequenceFlows.add(sequenceFlow); } }
// Check if there is a default sequence flow 检查是否有默认的序列流,默认的加入出线集合 // 出线为0且需计算条件(找出默认出线) if (outgoingSequenceFlows.size() == 0 && evaluateConditions) { // The elements that set this to false also have no support for default sequence flow if (defaultSequenceFlowId != null) { for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) { if (defaultSequenceFlowId.equals(sequenceFlow.getId())) { outgoingSequenceFlows.add(sequenceFlow); break; } } } }
// No outgoing found. Ending the execution 没有发现出线。结束执行 if (outgoingSequenceFlows.size() == 0) { if (flowNode.getOutgoingFlows() == null || flowNode.getOutgoingFlows().size() == 0) { logger.debug("No outgoing sequence flow found for flow node '{}'.", flowNode.getId()); Context.getAgenda().planEndExecutionOperation(execution); } else { thrownew ActivitiException("No outgoing sequence flow of element '" + flowNode.getId() + "' could be selected for continuing the process"); } } else {
// Leave, and reuse the incoming sequence flow, make executions for all the others (if applicable)
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager(); List<ExecutionEntity> outgoingExecutions = new ArrayList<ExecutionEntity>(flowNode.getOutgoingFlows().size());
// Reuse existing one execution.setCurrentFlowElement(sequenceFlow); execution.setActive(true); outgoingExecutions.add((ExecutionEntity) execution);
// Executions for all the other one //大于一个出线,则为所有的出线入库(并行网关等...) if (outgoingSequenceFlows.size() > 1) { for (int i = 1; i < outgoingSequenceFlows.size(); i++) {
// Leave (only done when all executions have been made, since some queries depend on this) 离开(仅在所有执行完成后才完成,因为某些查询依赖于此) for (ExecutionEntity outgoingExecution : outgoingExecutions) { Context.getAgenda().planContinueProcessOperation(outgoingExecution); } } }