@VisibleForTesting
  static <T> T tryFor(long timeout, TimeUnit timeoutUnit,
      long interval, TimeUnit intervalUnit,
      Supplier<T> supplier,
      Predicate<T> predicate,
      Timer timer) throws TimeoutException, InterruptedException {
    long until = timer.nanoTime() + NANOSECONDS.convert(timeout, timeoutUnit);
    long intervalNano = NANOSECONDS.convert(interval, intervalUnit);

    T value;
    for (;;) {
      value = supplier.get();
      if (predicate.test(value)) {
        return value;
      } else {
        // if there is still more time left after we sleep for interval period, then sleep and retry
        // otherwise break out and throw TimeoutException
        if ((timer.nanoTime() + intervalNano) < until) {
          timer.sleep(intervalNano);
        } else {
          break;
        }
      }
    }

    throw new TimeoutException();
  }
Try the supplier function until the predicate is true or timeout occurs.

@param timeout to retry for
@param timeoutUnit the unit for timeout
@param interval time between each try
@param intervalUnit the unit for interval
@param supplier to execute until predicate is true or times out
@param predicate to test for retry
@param <T> type of return value
@return value from supplier after it passes predicate or times out.
geode-common/src/main/java/org/apache/geode/internal/utils/Retry.java