Java Code Examples for org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution#inactivate()

The following examples show how to use org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution#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: ParallelGatewayActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {

    // Join
    PvmActivity activity = execution.getActivity();
    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();

    execution.inactivate();
    lockConcurrentRoot(execution);

    List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
    int nbrOfExecutionsToJoin = execution.getActivity().getIncomingTransitions().size();
    int nbrOfExecutionsJoined = joinedExecutions.size();

    if (nbrOfExecutionsJoined==nbrOfExecutionsToJoin) {

      // Fork
      LOG.activityActivation(activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
      execution.leaveActivityViaTransitions(outgoingTransitions, joinedExecutions);

    } else {
      LOG.noActivityActivation(activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
    }
  }
 
Example 2
Source File: ParallelGateway.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void execute(ActivityExecution execution) {
  PvmActivity activity = execution.getActivity();

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

  execution.inactivate();

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

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

  if (nbrOfExecutionsJoined==nbrOfExecutionsToJoin) {
    LOG.debug("parallel gateway '"+activity.getId()+"' activates: "+nbrOfExecutionsJoined+" of "+nbrOfExecutionsToJoin+" joined");
    execution.leaveActivityViaTransitions(outgoingTransitions, joinedExecutions);

  } else {
    LOG.debug("parallel gateway '"+activity.getId()+"' does not activate: "+nbrOfExecutionsJoined+" of "+nbrOfExecutionsToJoin+" joined");
  }
}
 
Example 3
Source File: ParallelMultiInstanceActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void prepareScopeExecution(ActivityExecution scopeExecution, int nrOfInstances) {
  // set the MI-body scoped variables
  setLoopVariable(scopeExecution, NUMBER_OF_INSTANCES, nrOfInstances);
  setLoopVariable(scopeExecution, NUMBER_OF_COMPLETED_INSTANCES, 0);
  setLoopVariable(scopeExecution, NUMBER_OF_ACTIVE_INSTANCES, nrOfInstances);
  scopeExecution.setActivity(null);
  scopeExecution.inactivate();
}
 
Example 4
Source File: ParallelMultiInstanceActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void concurrentChildExecutionEnded(ActivityExecution scopeExecution, ActivityExecution endedExecution) {

  int nrOfCompletedInstances = getLoopVariable(scopeExecution, NUMBER_OF_COMPLETED_INSTANCES) + 1;
  setLoopVariable(scopeExecution, NUMBER_OF_COMPLETED_INSTANCES, nrOfCompletedInstances);
  int nrOfActiveInstances = getLoopVariable(scopeExecution, NUMBER_OF_ACTIVE_INSTANCES) - 1;
  setLoopVariable(scopeExecution, NUMBER_OF_ACTIVE_INSTANCES, nrOfActiveInstances);

  // inactivate the concurrent execution
  endedExecution.inactivate();
  endedExecution.setActivityInstanceId(null);

  // join
  scopeExecution.forceUpdate();
  // TODO: should the completion condition be evaluated on the scopeExecution or on the endedExecution?
  if(completionConditionSatisfied(endedExecution) ||
      allExecutionsEnded(scopeExecution, endedExecution)) {

    ArrayList<ActivityExecution> childExecutions = new ArrayList<ActivityExecution>(((PvmExecutionImpl) scopeExecution).getNonEventScopeExecutions());
    for (ActivityExecution childExecution : childExecutions) {
      // delete all not-ended instances; these are either active (for non-scope tasks) or inactive but have no activity id (for subprocesses, etc.)
      if (childExecution.isActive() || childExecution.getActivity() == null) {
        ((PvmExecutionImpl)childExecution).deleteCascade("Multi instance completion condition satisfied.");
      }
      else {
        childExecution.remove();
      }
    }

    scopeExecution.setActivity((PvmActivity) endedExecution.getActivity().getFlowScope());
    scopeExecution.setActive(true);
    leave(scopeExecution);
  } else {
    ((ExecutionEntity) scopeExecution).dispatchDelayedEventsAndPerformOperation((Callback<PvmExecutionImpl, Void>) null);
  }
}
 
Example 5
Source File: InclusiveGatewayActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {

    execution.inactivate();
    lockConcurrentRoot(execution);

    PvmActivity activity = execution.getActivity();
    if (activatesGateway(execution, activity)) {

      LOG.activityActivation(activity.getId());

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

      // find matching non-default sequence flows
      for (PvmTransition outgoingTransition : execution.getActivity().getOutgoingTransitions()) {
        if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
          Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
          if (condition == null || condition.evaluate(execution)) {
            transitionsToTake.add(outgoingTransition);
          }
        }
      }

      // if none found, add default flow
      if (transitionsToTake.isEmpty()) {
        if (defaultSequenceFlow != null) {
          PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
          if (defaultTransition == null) {
            throw LOG.missingDefaultFlowException(execution.getActivity().getId(), defaultSequenceFlow);
          }

          transitionsToTake.add(defaultTransition);

        } else {
          // No sequence flow could be found, not even a default one
          throw LOG.stuckExecutionException(execution.getActivity().getId());
        }
      }

      // take the flows found
      execution.leaveActivityViaTransitions(transitionsToTake, joinedExecutions);
    } else {
      LOG.noActivityActivation(activity.getId());
    }
  }