@Test public void test11() { AtomicInteger ato = new AtomicInteger(0); RetryBuilder.<Integer>newBuilder().retryIfResult(rs -> rs < 31).withMaxDelay(500) .withBlock(r -> ThreadUtils.sleep(100)).build().call(ato::incrementAndGet); Assert.assertEquals(6, ato.get()); }
public T call(Callable<T> callable) { long startTime = System.currentTimeMillis(); long attemptNumbers = 0; while (true) { attemptNumbers++; final Attempt<T> attempt = attempt(callable, attemptNumbers, startTime); retryListeners.forEach(listener -> listener.accept(attempt)); if (!retryPredicate.test(attempt)) { if (attempt.hasException()) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } else { successListeners.forEach(listener -> listener.accept(attempt)); return attempt.getResult(); } } if (stopPredicate.test(attempt)) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } blockConsumer.accept(attempt); } }
Retryer { public T call(Callable<T> callable) { long startTime = System.currentTimeMillis(); long attemptNumbers = 0; while (true) { attemptNumbers++; final Attempt<T> attempt = attempt(callable, attemptNumbers, startTime); retryListeners.forEach(listener -> listener.accept(attempt)); if (!retryPredicate.test(attempt)) { if (attempt.hasException()) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } else { successListeners.forEach(listener -> listener.accept(attempt)); return attempt.getResult(); } } if (stopPredicate.test(attempt)) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } blockConsumer.accept(attempt); } } }
Retryer { public T call(Callable<T> callable) { long startTime = System.currentTimeMillis(); long attemptNumbers = 0; while (true) { attemptNumbers++; final Attempt<T> attempt = attempt(callable, attemptNumbers, startTime); retryListeners.forEach(listener -> listener.accept(attempt)); if (!retryPredicate.test(attempt)) { if (attempt.hasException()) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } else { successListeners.forEach(listener -> listener.accept(attempt)); return attempt.getResult(); } } if (stopPredicate.test(attempt)) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } blockConsumer.accept(attempt); } }  }
Retryer { public T call(Callable<T> callable) { long startTime = System.currentTimeMillis(); long attemptNumbers = 0; while (true) { attemptNumbers++; final Attempt<T> attempt = attempt(callable, attemptNumbers, startTime); retryListeners.forEach(listener -> listener.accept(attempt)); if (!retryPredicate.test(attempt)) { if (attempt.hasException()) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } else { successListeners.forEach(listener -> listener.accept(attempt)); return attempt.getResult(); } } if (stopPredicate.test(attempt)) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } blockConsumer.accept(attempt); } }  T call(Callable<T> callable); }
Retryer { public T call(Callable<T> callable) { long startTime = System.currentTimeMillis(); long attemptNumbers = 0; while (true) { attemptNumbers++; final Attempt<T> attempt = attempt(callable, attemptNumbers, startTime); retryListeners.forEach(listener -> listener.accept(attempt)); if (!retryPredicate.test(attempt)) { if (attempt.hasException()) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } else { successListeners.forEach(listener -> listener.accept(attempt)); return attempt.getResult(); } } if (stopPredicate.test(attempt)) { failListeners.forEach(listener -> listener.accept(attempt)); return null; } blockConsumer.accept(attempt); } }  T call(Callable<T> callable);  }