protected void eventNotificationsCompleted(PvmExecutionImpl execution) {
   ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
   ProcessInstanceStartContext processInstanceStartContext =
       execution.getProcessInstanceStartContext();
   List<ActivityImpl> initialActivityStack =
       processDefinition.getInitialActivityStack(processInstanceStartContext.getInitial());
   execution.setActivity(initialActivityStack.get(0));
   execution.performOperation(PROCESS_START_INITIAL);
 }
 protected PvmExecutionImpl eventNotificationsStarted(PvmExecutionImpl execution) {
   // Note: the following method call initializes the property
   // "processInstanceStartContext" on the given execution.
   // Do not remove it!
   execution.getProcessInstanceStartContext();
   return execution;
 }
  @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);
    }
  }
 protected ScopeImpl getScope(PvmExecutionImpl execution) {
   return execution.getProcessDefinition();
 }
 @Override
 public boolean isAsync(PvmExecutionImpl execution) {
   ProcessInstanceStartContext startContext = execution.getProcessInstanceStartContext();
   return startContext != null && startContext.isAsync();
 }