code: public JobResult waitForJobState(String jobname, CrawlControllerState state, int tries, int interval) {
          JobResult jobResult = null;
          if (tries <= 0) {
              tries = 1;
          }
          if (interval <= 99) {
              interval = 1000;
          }
          boolean bLoop = true;
          while (bLoop && tries > 0) {
              jobResult = job(jobname);
              // debug
              //System.out.println(jobResult.status + " - " + ResultStatus.OK);
              if (jobResult.status == ResultStatus.OK) {
                  // debug
                  //System.out.println(jobResult.job.crawlControllerState + " - " + state.name());
                  if ((state == null && jobResult.job.crawlControllerState == null) || (state != null && state.name().equals(jobResult.job.crawlControllerState))) {
                      bLoop = false;
                  }
              }
              --tries;
              if (bLoop && tries > 0) {
                  try {
                      Thread.sleep(interval);
                  } catch (InterruptedException e) {
                  }
              }
          }
          return jobResult;
      }
docs: TODO
  @param jobname
  @param state
  @param tries
  @param interval
  @return