protected ActivityBehavior setLoopCounterVariable(FlowNode flowNode) { ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior(); if (!(activityBehavior instanceof MultiInstanceActivityBehavior)) { throw new FlowableException("Programmatic error: expected multi instance activity behavior, but got " + activityBehavior.getClass()); } MultiInstanceActivityBehavior multiInstanceActivityBehavior = (MultiInstanceActivityBehavior) activityBehavior; String elementIndexVariable = multiInstanceActivityBehavior.getCollectionElementIndexVariable(); if (!flowNode.isAsynchronous()) { execution.setVariableLocal(elementIndexVariable, loopCounter); } else { multiInstanceRootExecution.setVariableLocal(elementIndexVariable, loopCounter); } return activityBehavior; }
Collection<String> flowNodeIdsWithInactivatedBehavior = new ArrayList<>(); for (FlowNode flowNode : process.findFlowElementsOfType(FlowNode.class)) { if (flowNode.getBehavior() instanceof InactiveActivityBehavior) { flowNodeIdsWithInactivatedBehavior.add(flowNode.getId()); InactiveActivityBehavior inactiveActivityBehavior = ((InactiveActivityBehavior) flowNode.getBehavior()); LOGGER.debug("Found InactiveActivityBehavior instance of class {} that can be executed on activity '{}'", inactiveActivityBehavior.getClass(), flowNode.getId()); inactiveActivityBehavior.executeInactive(inactiveExecution);
public static FlowableActivityEvent createActivityEvent(FlowableEngineEventType type, String activityId, String activityName, String executionId, String processInstanceId, String processDefinitionId, FlowElement flowElement) { FlowableActivityEventImpl newEvent = new FlowableActivityEventImpl(type); newEvent.setActivityId(activityId); newEvent.setActivityName(activityName); newEvent.setExecutionId(executionId); newEvent.setProcessDefinitionId(processDefinitionId); newEvent.setProcessInstanceId(processInstanceId); if (flowElement instanceof FlowNode) { FlowNode flowNode = (FlowNode) flowElement; newEvent.setActivityType(parseActivityType(flowNode)); Object behaviour = flowNode.getBehavior(); if (behaviour != null) { newEvent.setBehaviorClass(behaviour.getClass().getCanonicalName()); } } return newEvent; }
public static FlowableMultiInstanceActivityEvent createMultiInstanceActivityEvent(FlowableEngineEventType type, String activityId, String activityName, String executionId, String processInstanceId, String processDefinitionId, FlowElement flowElement) { FlowableMultiInstanceActivityEventImpl newEvent = new FlowableMultiInstanceActivityEventImpl(type); newEvent.setActivityId(activityId); newEvent.setActivityName(activityName); newEvent.setExecutionId(executionId); newEvent.setProcessDefinitionId(processDefinitionId); newEvent.setProcessInstanceId(processInstanceId); if (flowElement instanceof FlowNode) { FlowNode flowNode = (FlowNode) flowElement; newEvent.setActivityType(parseActivityType(flowNode)); Object behaviour = flowNode.getBehavior(); if (behaviour != null) { newEvent.setBehaviorClass(behaviour.getClass().getCanonicalName()); } newEvent.setSequential(((Activity) flowNode).getLoopCharacteristics().isSequential()); } return newEvent; }
@Override public void deleteProcessInstance(String processInstanceId, String deleteReason, boolean cascade) { ExecutionEntity processInstanceExecution = findById(processInstanceId); if (processInstanceExecution == null) { throw new FlowableObjectNotFoundException("No process instance found for id '" + processInstanceId + "'", ProcessInstance.class); } deleteProcessInstanceCascade(processInstanceExecution, deleteReason, cascade); // Special care needed for a process instance of a call activity: the parent process instance needs to be triggered for completion // This can't be added to the deleteProcessInstanceCascade method, as this will also trigger all child and/or multi-instance // process instances for child call activities, which shouldn't happen. if (processInstanceExecution.getSuperExecutionId() != null) { ExecutionEntity superExecution = processInstanceExecution.getSuperExecution(); if (superExecution != null && superExecution.getCurrentFlowElement() instanceof FlowNode && ((FlowNode) superExecution.getCurrentFlowElement()).getBehavior() instanceof SubProcessActivityBehavior) { SubProcessActivityBehavior subProcessActivityBehavior = (SubProcessActivityBehavior) ((FlowNode) superExecution.getCurrentFlowElement()).getBehavior(); try { subProcessActivityBehavior.completing(superExecution, processInstanceExecution); superExecution.setSubProcessInstance(null); subProcessActivityBehavior.completed(superExecution); } catch (Exception e) { throw new FlowableException("Could not complete parent process instance for call activity with process instance execution " + processInstanceExecution.getId(), e); } } } }
if (superExecution != null) { FlowNode superExecutionElement = (FlowNode) superExecution.getCurrentFlowElement(); subProcessActivityBehavior = (SubProcessActivityBehavior) superExecutionElement.getBehavior(); try { subProcessActivityBehavior.completing(superExecution, processInstanceExecution);
sourceFlowElement != null ? sourceFlowElement.getName() : null, sourceFlowElement != null ? sourceFlowElement.getClass().getName() : null, sourceFlowElement != null ? ((FlowNode) sourceFlowElement).getBehavior() : null, targetFlowElement != null ? targetFlowElement.getId() : null, targetFlowElement != null ? targetFlowElement.getName() : null, targetFlowElement != null ? targetFlowElement.getClass().getName() : null, targetFlowElement != null ? ((FlowNode) targetFlowElement).getBehavior() : null));
public static FlowableMultiInstanceActivityCompletedEvent createMultiInstanceActivityCompletedEvent(FlowableEngineEventType type, int numberOfInstances, int numberOfActiveInstances, int numberOfCompletedInstances, String activityId, String activityName, String executionId, String processInstanceId, String processDefinitionId, FlowElement flowElement) { FlowableMultiInstanceActivityCompletedEventImpl newEvent = new FlowableMultiInstanceActivityCompletedEventImpl(type); newEvent.setNumberOfInstances(numberOfInstances); newEvent.setNumberOfActiveInstances(numberOfActiveInstances); newEvent.setNumberOfCompletedInstances(numberOfCompletedInstances); newEvent.setActivityId(activityId); newEvent.setActivityName(activityName); newEvent.setExecutionId(executionId); newEvent.setProcessDefinitionId(processDefinitionId); newEvent.setProcessInstanceId(processInstanceId); if (flowElement instanceof FlowNode) { FlowNode flowNode = (FlowNode) flowElement; newEvent.setActivityType(parseActivityType(flowNode)); Object behaviour = flowNode.getBehavior(); if (behaviour != null) { newEvent.setBehaviorClass(behaviour.getClass().getCanonicalName()); } newEvent.setSequential(((Activity) flowNode).getLoopCharacteristics().isSequential()); } return newEvent; }
if (currentFlowElement instanceof FlowNode) { ActivityBehavior activityBehavior = (ActivityBehavior) ((FlowNode) currentFlowElement).getBehavior(); if (activityBehavior instanceof TriggerableActivityBehavior) {
protected void executeSynchronous(FlowNode flowNode) { CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(execution); // Execution listener: event 'start' if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START); } // Create any boundary events, sub process boundary events will be created from the activity behavior List<ExecutionEntity> boundaryEventExecutions = null; List<BoundaryEvent> boundaryEvents = null; if (!inCompensation && flowNode instanceof Activity) { // Only activities can have boundary events boundaryEvents = ((Activity) flowNode).getBoundaryEvents(); if (CollectionUtil.isNotEmpty(boundaryEvents)) { boundaryEventExecutions = createBoundaryEvents(boundaryEvents, execution); } } // Execute actual behavior ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior(); if (activityBehavior != null) { executeActivityBehavior(activityBehavior, flowNode); executeBoundaryEvents(boundaryEvents, boundaryEventExecutions); } else { executeBoundaryEvents(boundaryEvents, boundaryEventExecutions); LOGGER.debug("No activityBehavior on activity '{}' with execution {}", flowNode.getId(), execution.getId()); CommandContextUtil.getAgenda().planTakeOutgoingSequenceFlowsOperation(execution, true); } }
protected void executeSynchronous(FlowNode flowNode) { CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordActivityStart(execution); // Execution listener if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START); } // Execute actual behavior ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior(); LOGGER.debug("Executing activityBehavior {} on activity '{}' with execution {}", activityBehavior.getClass(), flowNode.getId(), execution.getId()); ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); if (processEngineConfiguration != null && processEngineConfiguration.getEventDispatcher().isEnabled()) { processEngineConfiguration.getEventDispatcher().dispatchEvent( FlowableEventBuilder.createActivityEvent(FlowableEngineEventType.ACTIVITY_STARTED, flowNode.getId(), flowNode.getName(), execution.getId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), flowNode)); } try { activityBehavior.execute(execution); } catch (BpmnError error) { // re-throw business fault so that it can be caught by an Error Intermediate Event or Error Event Sub-Process in the process ErrorPropagation.propagateError(error, execution); } catch (RuntimeException e) { if (LogMDC.isMDCEnabled()) { LogMDC.putMDCExecution(execution); } throw e; } }
protected void executeMultiInstanceSynchronous(FlowNode flowNode) { // Execution listener: event 'start' if (CollectionUtil.isNotEmpty(flowNode.getExecutionListeners())) { executeExecutionListeners(flowNode, ExecutionListener.EVENTNAME_START); } if (!hasMultiInstanceRootExecution(execution, flowNode)) { execution = createMultiInstanceRootExecution(execution); } // Create any boundary events, sub process boundary events will be created from the activity behavior List<ExecutionEntity> boundaryEventExecutions = null; List<BoundaryEvent> boundaryEvents = null; if (!inCompensation && flowNode instanceof Activity) { // Only activities can have boundary events boundaryEvents = ((Activity) flowNode).getBoundaryEvents(); if (CollectionUtil.isNotEmpty(boundaryEvents)) { boundaryEventExecutions = createBoundaryEvents(boundaryEvents, execution); } } // Execute the multi instance behavior ActivityBehavior activityBehavior = (ActivityBehavior) flowNode.getBehavior(); if (activityBehavior != null) { executeActivityBehavior(activityBehavior, flowNode); executeBoundaryEvents(boundaryEvents, boundaryEventExecutions); } else { throw new FlowableException("Expected an activity behavior in flow node " + flowNode.getId()); } }