Function<REQUEST, RESPONSE> functionCall, Predicate<RESPONSE> terminationPredicate) { WaitContext context = new WaitContext(System.currentTimeMillis()); RESPONSE r = null; while (true) { return Optional.of(r); context.incrementAttempts(); context.setCurrentTime(System.currentTimeMillis());
@Override public long nextDelay(WaitContext context) { long delay = (long) Math.pow(2, context.getAttemptsMade()); delay *= 1000; if (delay <= 0) { return maxDelayInMillis; } return Math.min(delay, maxDelayInMillis); } }
@Override public boolean shouldTerminate(WaitContext context) { final long endTime = context.getStartTime() + maxTimeInMillis; final long currentTime = context.getCurrentTime(); return endTime <= currentTime; }
@Override public boolean shouldTerminate(WaitContext context) { return context.getAttemptsMade() < maxAttempts; } }