Java Code Examples for org.activiti.engine.impl.pvm.delegate.ActivityExecution#getActivity()

The following examples show how to use org.activiti.engine.impl.pvm.delegate.ActivityExecution#getActivity() . 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: ErrorPropagation.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
private static String findLocalErrorEventHandler(ActivityExecution execution, String errorCode) {
    PvmScope scope = execution.getActivity();
    while (scope != null) {

        @SuppressWarnings("unchecked")
        List<ErrorEventDefinition> definitions = (List<ErrorEventDefinition>) scope.getProperty(BpmnParse.PROPERTYNAME_ERROR_EVENT_DEFINITIONS);
        if (definitions != null) {
            // definitions are sorted by precedence, ie. event subprocesses first.
            for (ErrorEventDefinition errorEventDefinition : definitions) {
                if (errorEventDefinition.catches(errorCode)) {
                    return scope.findActivity(errorEventDefinition.getHandlerActivityId()).getId();
                }
            }
        }

        // search for error handlers in parent scopes
        if (scope instanceof PvmActivity) {
            scope = ((PvmActivity) scope).getParent();
        } else {
            scope = null;
        }
    }
    return null;
}
 
Example 3
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 4
Source File: SubProcessActivityBehavior.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;
    PvmActivity activity = activityExecution.getActivity();
    ActivityImpl initialActivity = (ActivityImpl) activity.getProperty(BpmnParse.PROPERTYNAME_INITIAL);

    if (initialActivity == null) {
        throw new ActivitiException("No initial activity found for subprocess "
                + activityExecution.getActivity().getId());
    }

    // initialize the template-defined data objects as variables
    initializeDataObjects(activityExecution, activity);

    if (initialActivity.getActivityBehavior() != null
            && initialActivity.getActivityBehavior() instanceof NoneStartEventActivityBehavior) { // embedded subprocess: only none start allowed
        ((ExecutionEntity) execution).setActivity(initialActivity);
        Context.getCommandContext().getHistoryManager().recordActivityStart((ExecutionEntity) execution);
    }

    activityExecution.executeActivity(initialActivity);
}
 
Example 5
Source File: TerminateEndEventActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(DelegateExecution delegateExecution) {
    ActivityExecution execution = (ActivityExecution) delegateExecution;
    ActivityImpl terminateEndEventActivity = (ActivityImpl) execution.getActivity();

    if (terminateAll) {
        ActivityExecution processInstanceExecution = findRootProcessInstanceExecution((ExecutionEntity) execution);
        terminateProcessInstanceExecution(execution, terminateEndEventActivity, processInstanceExecution);
    } else {
        ActivityExecution scopeExecution = ScopeUtil.findScopeExecution(execution);
        if (scopeExecution != null) {
            terminateExecution(execution, terminateEndEventActivity, scopeExecution);
        }
    }

}
 
Example 6
Source File: TerminateEndEventActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 7
Source File: CancelEndEventActivityBehavior.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;
    // find cancel boundary event:
    ActivityImpl cancelBoundaryEvent = ScopeUtil
            .findInParentScopesByBehaviorType((ActivityImpl) activityExecution.getActivity(), CancelBoundaryEventActivityBehavior.class);

    if (cancelBoundaryEvent == null) {
        throw new ActivitiException("Could not find cancel boundary event for cancel end event " + activityExecution.getActivity());
    }

    ActivityExecution scopeExecution = ScopeUtil.findScopeExecutionForScope((ExecutionEntity) execution, cancelBoundaryEvent.getParentActivity());

    // end all executions and process instances in the scope of the transaction
    scopeExecution.destroyScope("cancel end event fired");

    // the scope execution executes the boundary event
    InterpretableExecution outgoingExecution = (InterpretableExecution) scopeExecution;
    outgoingExecution.setActivity(cancelBoundaryEvent);
    outgoingExecution.setActive(true);

    // execute the boundary
    cancelBoundaryEvent
            .getActivityBehavior()
            .execute(outgoingExecution);
}
 
Example 8
Source File: EmbeddedSubProcess.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void timerFires(ActivityExecution execution, String signalName, Object signalData) throws Exception {
    PvmActivity timerActivity = execution.getActivity();
    boolean isInterrupting = (Boolean) timerActivity.getProperty("isInterrupting");
    List<ActivityExecution> recyclableExecutions;
    if (isInterrupting) {
        recyclableExecutions = removeAllExecutions(execution);
    } else {
        recyclableExecutions = Collections.EMPTY_LIST;
    }
    execution.takeAll(timerActivity.getOutgoingTransitions(), recyclableExecutions);
}
 
Example 9
Source File: EventScopeCreatingSubprocess.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void timerFires(ActivityExecution execution, String signalName, Object signalData) throws Exception {
    PvmActivity timerActivity = execution.getActivity();
    boolean isInterrupting = (Boolean) timerActivity.getProperty("isInterrupting");
    List<ActivityExecution> recyclableExecutions;
    if (isInterrupting) {
        recyclableExecutions = removeAllExecutions(execution);
    } else {
        recyclableExecutions = Collections.EMPTY_LIST;
    }
    execution.takeAll(timerActivity.getOutgoingTransitions(), recyclableExecutions);
}
 
Example 10
Source File: ExecutionImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public List<ActivityExecution> findInactiveConcurrentExecutions(PvmActivity activity) {
    List<ActivityExecution> inactiveConcurrentExecutionsInActivity = new ArrayList<>();
    List<ActivityExecution> otherConcurrentExecutions = new ArrayList<>();
    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 (LOGGER.isDebugEnabled()) {
        LOGGER.debug("inactive concurrent executions in '{}': {}", activity, inactiveConcurrentExecutionsInActivity);
        LOGGER.debug("other concurrent executions: {}", otherConcurrentExecutions);
    }
    return inactiveConcurrentExecutionsInActivity;
}
 
Example 11
Source File: ExecutionEntity.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public List<ActivityExecution> findInactiveConcurrentExecutions(PvmActivity activity) {
    List<ActivityExecution> inactiveConcurrentExecutionsInActivity = new ArrayList<>();
    List<ActivityExecution> otherConcurrentExecutions = new ArrayList<>();
    if (isConcurrent()) {
        List<? extends ActivityExecution> concurrentExecutions = getParent().getAllChildExecutions();
        for (ActivityExecution concurrentExecution : concurrentExecutions) {
            if (concurrentExecution.getActivity() != null && concurrentExecution.getActivity().getId().equals(activity.getId())) {
                if (!concurrentExecution.isActive()) {
                    inactiveConcurrentExecutionsInActivity.add(concurrentExecution);
                }
            } else {
                otherConcurrentExecutions.add(concurrentExecution);
            }
        }
    } else {
        if (!isActive()) {
            inactiveConcurrentExecutionsInActivity.add(this);
        } else {
            otherConcurrentExecutions.add(this);
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("inactive concurrent executions in '{}': {}", activity, inactiveConcurrentExecutionsInActivity);
        LOGGER.debug("other concurrent executions: {}", otherConcurrentExecutions);
    }
    return inactiveConcurrentExecutionsInActivity;
}
 
Example 12
Source File: InclusiveGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public boolean activeConcurrentExecutionsExist(ActivityExecution execution) {
    PvmActivity activity = execution.getActivity();
    if (execution.isConcurrent()) {
        for (ActivityExecution concurrentExecution : getLeaveExecutions(execution.getParent())) {
            if (concurrentExecution.isActive() && !concurrentExecution.getId().equals(execution.getId())) {
                // TODO: when is transitionBeingTaken cleared? Should we clear it?
                boolean reachable = false;
                PvmTransition pvmTransition = ((ExecutionEntity) concurrentExecution).getTransitionBeingTaken();
                if (pvmTransition != null) {
                    reachable = isReachable(pvmTransition.getDestination(), activity, new HashSet<>());
                } else {
                    reachable = isReachable(concurrentExecution.getActivity(), activity, new HashSet<>());
                }

                if (reachable) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("an active concurrent execution found: '{}'", concurrentExecution.getActivity());
                    }
                    return true;
                }
            }
        }
    } else if (execution.isActive()) { // is this ever true?
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("an active concurrent execution found: '{}'", execution.getActivity());
        }
        return true;
    }

    return false;
}
 
Example 13
Source File: IntermediateThrowSignalEventActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {

    CommandContext commandContext = Context.getCommandContext();

    List<SignalEventSubscriptionEntity> subscriptionEntities = null;
    if (processInstanceScope) {
        subscriptionEntities = commandContext
                .getEventSubscriptionEntityManager()
                .findSignalEventSubscriptionsByProcessInstanceAndEventName(execution.getProcessInstanceId(), signalDefinition.getEventName());
    } else {
        subscriptionEntities = commandContext
                .getEventSubscriptionEntityManager()
                .findSignalEventSubscriptionsByEventName(signalDefinition.getEventName(), execution.getTenantId());
    }

    for (SignalEventSubscriptionEntity signalEventSubscriptionEntity : subscriptionEntities) {
        ProcessDefinition processDefinition = ProcessDefinitionUtil.getProcessDefinition(signalEventSubscriptionEntity.getProcessDefinitionId());
        if (Flowable5Util.isVersion5Tag(processDefinition.getEngineVersion())) {
            signalEventSubscriptionEntity.eventReceived(null, signalDefinition.isAsync());
            
        } else {
            EventSubscriptionService eventSubscriptionService = CommandContextUtil.getEventSubscriptionService();
            EventSubscriptionEntity flowable6EventSubscription = eventSubscriptionService.findById(signalEventSubscriptionEntity.getId());
            EventSubscriptionUtil.eventReceived(flowable6EventSubscription, null, signalDefinition.isAsync());
        }
    }

    ActivityExecution activityExecution = (ActivityExecution) execution;
    if (activityExecution.getActivity() != null) { // don't continue if process has already finished
        leave(activityExecution);
    }
}
 
Example 14
Source File: BpmnActivityBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Performs the default outgoing BPMN 2.0 behavior, which is having parallel paths of executions for the outgoing sequence flow.
 * <p>
 * More precisely: every sequence flow that has a condition which evaluates to true (or which doesn't have a condition), is selected for continuation of the process instance. If multiple sequencer
 * flow are selected, multiple, parallel paths of executions are created.
 */
public void performDefaultOutgoingBehavior(ActivityExecution activityExecution) {
    ActivityImpl activity = (ActivityImpl) activityExecution.getActivity();
    if (!(activity.getActivityBehavior() instanceof IntermediateCatchEventActivityBehavior)) {
        dispatchJobCanceledEvents(activityExecution);
    }
    performOutgoingBehavior(activityExecution, true, false, null);
}
 
Example 15
Source File: WaitState.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
public void signal(ActivityExecution execution, String signalName, Object signalData) throws Exception {
    PvmActivity activity = execution.getActivity();
    System.out.println("触发活动" + activity.getId());

    PvmTransition transition = activity.getOutgoingTransitions().get(0);
    execution.take(transition);
}
 
Example 16
Source File: InclusiveGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    activityExecution.inactivate();
    lockConcurrentRoot(activityExecution);

    PvmActivity activity = activityExecution.getActivity();
    if (!activeConcurrentExecutionsExist(activityExecution)) {

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("inclusive gateway '{}' activates", activity.getId());
        }

        List<ActivityExecution> joinedExecutions = activityExecution.findInactiveConcurrentExecutions(activity);
        String defaultSequenceFlow = (String) activityExecution.getActivity().getProperty("default");
        List<PvmTransition> transitionsToTake = new ArrayList<>();

        for (PvmTransition outgoingTransition : activityExecution.getActivity().getOutgoingTransitions()) {

            Expression skipExpression = outgoingTransition.getSkipExpression();
            if (!SkipExpressionUtil.isSkipExpressionEnabled(activityExecution, 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(activityExecution, skipExpression)) {
                transitionsToTake.add(outgoingTransition);
            }
        }

        if (!transitionsToTake.isEmpty()) {
            activityExecution.takeAll(transitionsToTake, joinedExecutions);

        } else {

            if (defaultSequenceFlow != null) {
                PvmTransition defaultTransition = activityExecution.getActivity().findOutgoingTransition(defaultSequenceFlow);
                if (defaultTransition != null) {
                    activityExecution.take(defaultTransition);
                } 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 '"
                                + activityExecution.getActivity().getId()
                                + "' could be selected for continuing the process");
            }
        }

    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Inclusive gateway '{}' does not activate", activity.getId());
        }
    }
}