code: private ResourceReport getResourceReport(TwillController controller, int maxWaitMs) {
      ResourceReport report = controller.getResourceReport();
      int elapsed = 0;
      while (report == null) {
        report = controller.getResourceReport();
        try {
          Thread.sleep(500);
        } catch (InterruptedException e) {
          throw new IllegalStateException(e);
        }
        elapsed += 500;
        if ((maxWaitMs != -1) && (elapsed > maxWaitMs)) {
          String msg = String.format("Exceeded max wait time to retrieve ResourceReport from Twill."
              + " Elapsed time = %s ms", elapsed);
          log.error(msg);
          throw new IllegalStateException(msg);
        }
        if ((elapsed % 10000) == 0) {
          log.info("Waiting for ResourceReport from Twill. Elapsed time = {} ms", elapsed);
        }
      }
      return report;
    }
docs: Attempts to retrieves ResourceReport until maxWaitMs time is reached. Set maxWaitMs to -1 to
  retry forever.