Java Code Examples for org.flowable.engine.delegate.DelegateExecution#inactivate()

The following examples show how to use org.flowable.engine.delegate.DelegateExecution#inactivate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParallelGateway.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    PvmActivity activity = activityExecution.getActivity();

    List<PvmTransition> outgoingTransitions = activityExecution.getActivity().getOutgoingTransitions();

    execution.inactivate();

    List<ActivityExecution> joinedExecutions = activityExecution.findInactiveConcurrentExecutions(activity);

    int nbrOfExecutionsToJoin = activityExecution.getActivity().getIncomingTransitions().size();
    int nbrOfExecutionsJoined = joinedExecutions.size();

    if (nbrOfExecutionsJoined == nbrOfExecutionsToJoin) {
        LOGGER.debug("parallel gateway '{}' activates: {} of {} joined", activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
        activityExecution.takeAll(outgoingTransitions, joinedExecutions);

    } else if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("parallel gateway '{}' does not activate: {} of {} joined", activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
    }
}
 
Example 2
Source File: ParallelGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    // Join
    PvmActivity activity = activityExecution.getActivity();
    List<PvmTransition> outgoingTransitions = activityExecution.getActivity().getOutgoingTransitions();
    execution.inactivate();
    lockConcurrentRoot(activityExecution);

    List<ActivityExecution> joinedExecutions = activityExecution.findInactiveConcurrentExecutions(activity);
    int nbrOfExecutionsToJoin = activityExecution.getActivity().getIncomingTransitions().size();
    int nbrOfExecutionsJoined = joinedExecutions.size();
    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution);
    if (nbrOfExecutionsJoined == nbrOfExecutionsToJoin) {

        // Fork
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("parallel gateway '{}' activates: {} of {} joined", activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
        }
        activityExecution.takeAll(outgoingTransitions, joinedExecutions);

    } else if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("parallel gateway '{}' does not activate: {} of {} joined", activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
    }
}
 
Example 3
Source File: InclusiveGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    // The join in the inclusive gateway works as follows:
    // When an execution enters it, it is inactivated.
    // All the inactivated executions stay in the inclusive gateway
    // until ALL executions that CAN reach the inclusive gateway have reached it.
    //
    // This check is repeated on execution changes until the inactivated
    // executions leave the gateway.

    execution.inactivate();
    executeInclusiveGatewayLogic((ExecutionEntity) execution, false);
}
 
Example 4
Source File: ParallelGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {

    // First off all, deactivate the execution
    execution.inactivate();

    // Join
    FlowElement flowElement = execution.getCurrentFlowElement();
    ParallelGateway parallelGateway = null;
    if (flowElement instanceof ParallelGateway) {
        parallelGateway = (ParallelGateway) flowElement;
    } else {
        throw new FlowableException("Programmatic error: parallel gateway behaviour can only be applied" + " to a ParallelGateway instance, but got an instance of " + flowElement);
    }

    lockFirstParentScope(execution);

    DelegateExecution multiInstanceExecution = null;
    if (hasMultiInstanceParent(parallelGateway)) {
        multiInstanceExecution = findMultiInstanceParentExecution(execution);
    }

    ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
    Collection<ExecutionEntity> joinedExecutions = executionEntityManager.findInactiveExecutionsByActivityIdAndProcessInstanceId(execution.getCurrentActivityId(), execution.getProcessInstanceId());
    if (multiInstanceExecution != null) {
        joinedExecutions = cleanJoinedExecutions(joinedExecutions, multiInstanceExecution);
    }

    int nbrOfExecutionsToJoin = parallelGateway.getIncomingFlows().size();
    int nbrOfExecutionsCurrentlyJoined = joinedExecutions.size();

    // Fork

    // Is needed to set the endTime for all historic activity joins
    CommandContextUtil.getActivityInstanceEntityManager().recordActivityEnd((ExecutionEntity) execution, null);

    if (nbrOfExecutionsCurrentlyJoined == nbrOfExecutionsToJoin) {

        // Fork
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("parallel gateway '{}' ({}) activates: {} of {} joined", execution.getCurrentActivityId(), 
                    execution.getId(), nbrOfExecutionsCurrentlyJoined, nbrOfExecutionsToJoin);
        }

        if (parallelGateway.getIncomingFlows().size() > 1) {

            // All (now inactive) children are deleted.
            for (ExecutionEntity joinedExecution : joinedExecutions) {

                // The current execution will be reused and not deleted
                if (!joinedExecution.getId().equals(execution.getId())) {
                    executionEntityManager.deleteRelatedDataForExecution(joinedExecution, null);
                    executionEntityManager.delete(joinedExecution);
                }

            }
        }

        // TODO: potential optimization here: reuse more then 1 execution, only 1 currently
        CommandContextUtil.getAgenda().planTakeOutgoingSequenceFlowsOperation((ExecutionEntity) execution, false); // false -> ignoring conditions on parallel gw

    } else if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("parallel gateway '{}' ({}) does not activate: {} of {} joined", execution.getCurrentActivityId(), 
                execution.getId(), nbrOfExecutionsCurrentlyJoined, nbrOfExecutionsToJoin);
    }

}
 
Example 5
Source File: ParallelMultiInstanceBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * Called when the wrapped {@link ActivityBehavior} calls the {@link AbstractBpmnActivityBehavior#leave(DelegateExecution)} method. Handles the completion of one of the parallel instances
 */
@Override
public void leave(DelegateExecution execution) {

    boolean zeroNrOfInstances = false;
    if (resolveNrOfInstances(execution) == 0) {
        // Empty collection, just leave.
        zeroNrOfInstances = true;
        super.leave(execution); // Plan the default leave
    }

    int loopCounter = getLoopVariable(execution, getCollectionElementIndexVariable());
    int nrOfInstances = getLoopVariable(execution, NUMBER_OF_INSTANCES);
    int nrOfCompletedInstances = getLoopVariable(execution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
    int nrOfActiveInstances = getLoopVariable(execution, NUMBER_OF_ACTIVE_INSTANCES) - 1;
    
    DelegateExecution miRootExecution = getMultiInstanceRootExecution(execution);
    if (miRootExecution != null) { // will be null in case of empty collection
        setLoopVariable(miRootExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
        setLoopVariable(miRootExecution, NUMBER_OF_ACTIVE_INSTANCES, nrOfActiveInstances);
    }

    CommandContextUtil.getActivityInstanceEntityManager().recordActivityEnd((ExecutionEntity) execution, null);
    callActivityEndListeners(execution);
    
    logLoopDetails(execution, "instance completed", loopCounter, nrOfCompletedInstances, nrOfActiveInstances, nrOfInstances);

    if (zeroNrOfInstances) {
        return;
    }

    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    if (executionEntity.getParent() != null) {

        executionEntity.inactivate();
        lockFirstParentScope(executionEntity);

        boolean isCompletionConditionSatisfied = completionConditionSatisfied(execution.getParent());
        if (nrOfCompletedInstances >= nrOfInstances || isCompletionConditionSatisfied) {

            ExecutionEntity leavingExecution = null;
            if (nrOfInstances > 0) {
                leavingExecution = executionEntity.getParent();
            } else {
                CommandContextUtil.getActivityInstanceEntityManager().recordActivityEnd((ExecutionEntity) execution, null);
                leavingExecution = executionEntity;
            }

            Activity activity = (Activity) execution.getCurrentFlowElement();
            verifyCompensation(execution, leavingExecution, activity);
            verifyCallActivity(leavingExecution, activity);
            
            if (isCompletionConditionSatisfied) {
                LinkedList<DelegateExecution> toVerify = new LinkedList<>(miRootExecution.getExecutions());
                while (!toVerify.isEmpty()) {
                    DelegateExecution childExecution = toVerify.pop();
                    if (((ExecutionEntity) childExecution).isInserted()) {
                        childExecution.inactivate();
                    }
                    
                    List<DelegateExecution> childExecutions = (List<DelegateExecution>) childExecution.getExecutions();
                    if (childExecutions != null && !childExecutions.isEmpty()) {
                        toVerify.addAll(childExecutions);
                    }
                }
                sendCompletedWithConditionEvent(leavingExecution);
            }
            else {
                sendCompletedEvent(leavingExecution);
            }

            super.leave(leavingExecution);
          }

    } else {
        sendCompletedEvent(execution);
        super.leave(execution);
    }
}