private void updateStatus() {
    int completed = 0;
    List<TaskInfo> taskInfoList = mJobInfo.getTaskInfoList();
    for (TaskInfo info : taskInfoList) {
      switch (info.getStatus()) {
        case FAILED:
          mJobInfo.setStatus(Status.FAILED);
          if (mJobInfo.getErrorMessage().isEmpty()) {
            mJobInfo.setErrorMessage("Task execution failed: " + info.getErrorMessage());
          }
          return;
        case CANCELED:
          if (mJobInfo.getStatus() != Status.FAILED) {
            mJobInfo.setStatus(Status.CANCELED);
          }
          return;
        case RUNNING:
          if (mJobInfo.getStatus() != Status.FAILED && mJobInfo.getStatus() != Status.CANCELED) {
            mJobInfo.setStatus(Status.RUNNING);
          }
          break;
        case COMPLETED:
          completed++;
          break;
        case CREATED:
          // do nothing
          break;
        default:
          throw new IllegalArgumentException("Unsupported status " + info.getStatus());
      }
    }
    if (completed == taskInfoList.size()) {
      if (mJobInfo.getStatus() == Status.COMPLETED) {
        return;
      }

      // all the tasks completed, run join
      try {
        mJobInfo.setStatus(Status.COMPLETED);
        mJobInfo.setResult(join(taskInfoList));
      } catch (Exception e) {
        mJobInfo.setStatus(Status.FAILED);
        mJobInfo.setErrorMessage(e.getMessage());
      }
    }
  }
private void updateStatus ( ) { int completed = 0 ; List < TaskInfo > taskInfoList = mJobInfo . getTaskInfoList ( ) ; for ( TaskInfo info : taskInfoList ) { switch ( info . getStatus ( ) ) { case FAILED : mJobInfo . setStatus ( Status . FAILED ) ; if ( mJobInfo . getErrorMessage ( ) . isEmpty ( ) ) { mJobInfo . setErrorMessage ( "Task execution failed: " + info . getErrorMessage ( ) ) ; } return ; case CANCELED : if ( mJobInfo . getStatus ( ) != Status . FAILED ) { mJobInfo . setStatus ( Status . CANCELED ) ; } return ; case RUNNING : if ( mJobInfo . getStatus ( ) != Status . FAILED && mJobInfo . getStatus ( ) != Status . CANCELED ) { mJobInfo . setStatus ( Status . RUNNING ) ; } break ; case COMPLETED : completed ++ ; break ; case CREATED : break ; default : throw new IllegalArgumentException ( "Unsupported status " + info . getStatus ( ) ) ; } } if ( completed == taskInfoList . size ( ) ) { if ( mJobInfo . getStatus ( ) == Status . COMPLETED ) { return ; } try { mJobInfo . setStatus ( Status . COMPLETED ) ; mJobInfo . setResult ( join ( taskInfoList ) ) ; } catch ( Exception e ) { mJobInfo . setStatus ( Status . FAILED ) ; mJobInfo . setErrorMessage ( e . getMessage ( ) ) ; } } }
Updates the status of the job. When all the tasks are completed, run the join method in the
definition.