/** * Builds the retryer. * * @return the built retryer. */ public Retryer<V> build() { AttemptTimeLimiter<V> theAttemptTimeLimiter = attemptTimeLimiter == null ? AttemptTimeLimiters.<V>noTimeLimit() : attemptTimeLimiter; StopStrategy theStopStrategy = stopStrategy == null ? StopStrategies.neverStop() : stopStrategy; WaitStrategy theWaitStrategy = waitStrategy == null ? WaitStrategies.noWait() : waitStrategy; BlockStrategy theBlockStrategy = blockStrategy == null ? BlockStrategies.threadSleepStrategy() : blockStrategy; return new Retryer<V>(theAttemptTimeLimiter, theStopStrategy, theWaitStrategy, theBlockStrategy, rejectionPredicate, listeners); }
retryerBuilder.withWaitStrategy(WaitStrategies.exponentialWait(backoffMax, TimeUnit.MILLISECONDS)); } else { retryerBuilder.withWaitStrategy(WaitStrategies.noWait());
/** * Builds the retryer. * * @return the built retryer. */ public Retryer build() { AttemptTimeLimiter theAttemptTimeLimiter = attemptTimeLimiter == null ? AttemptTimeLimiters.noTimeLimit() : attemptTimeLimiter; StopStrategy theStopStrategy = stopStrategy == null ? StopStrategies.neverStop() : stopStrategy; WaitStrategy theWaitStrategy = waitStrategy == null ? WaitStrategies.noWait() : waitStrategy; BlockStrategy theBlockStrategy = blockStrategy == null ? BlockStrategies.threadSleepStrategy() : blockStrategy; return new Retryer( theAttemptTimeLimiter, theStopStrategy, theWaitStrategy, theBlockStrategy, retryPredicates, listeners); }
@Test public void testNoWait() { WaitStrategy noWait = WaitStrategies.noWait(); assertEquals(0L, noWait.computeSleepTime(failedAttempt(18, 9879L))); }
public JSONFetcher(int timeout, int retries, int minBackoff, int maxBackoff) { Preconditions.checkArgument(retries >= 0, "retries argument must be a non-negative integer"); this.timeout = timeout; RetryerBuilder<byte[]> retryerBuilder = RetryerBuilder .<byte[]>newBuilder() .retryIfExceptionOfType(IOException.class) .withStopStrategy(StopStrategies.stopAfterAttempt(retries + 1)); if ((minBackoff > 0) && (maxBackoff > 0)) { retryerBuilder.withWaitStrategy(WaitStrategies.exponentialWait( minBackoff, maxBackoff, TimeUnit.MILLISECONDS)); } else { retryerBuilder.withWaitStrategy(WaitStrategies.noWait()); } retryer = retryerBuilder.build(); }