public static R retry()

in maven-resolver-named-locks/src/main/java/org/eclipse/aether/named/support/Retry.java [59:97]


    public static <R> R retry(
            final long time,
            final TimeUnit unit,
            final long sleepMillis,
            final Callable<R> operation,
            final Predicate<Exception> retryPredicate,
            final R defaultResult)
            throws InterruptedException {
        long now = System.nanoTime();
        final long barrier = now + unit.toNanos(time);
        int attempt = 1;
        R result = null;
        while (now < barrier && result == null) {
            try {
                result = operation.call();
                if (result == null) {
                    LOGGER.trace("Retry attempt {}: no result", attempt);
                    Thread.sleep(sleepMillis);
                }
            } catch (InterruptedException e) {
                throw e;
            } catch (Exception e) {
                LOGGER.trace("Retry attempt {}: operation failure", attempt, e);
                if (e instanceof DoNotRetry) {
                    if (e instanceof RuntimeException) {
                        throw (RuntimeException) e;
                    } else {
                        throw new IllegalStateException(e);
                    }
                }
                if (retryPredicate != null && !retryPredicate.test(e)) {
                    throw new IllegalStateException(e);
                }
            }
            now = System.nanoTime();
            attempt++;
        }
        return result == null ? defaultResult : result;
    }