V - the type of the call return valuepublic final class Retryer<V> extends Object
RetryerBuilder. A retryer
is thread-safe, provided the arguments passed to its constructor are thread-safe.| 限定符和类型 | 类和说明 |
|---|---|
static class |
Retryer.RetryerCallable<X>
|
| 构造器和说明 |
|---|
Retryer(AttemptTimeLimiter<V> attemptTimeLimiter,
StopStrategy stopStrategy,
WaitStrategy waitStrategy,
BlockStrategy blockStrategy,
com.google.common.base.Predicate<Attempt<V>> rejectionPredicate)
Constructor
|
Retryer(AttemptTimeLimiter<V> attemptTimeLimiter,
StopStrategy stopStrategy,
WaitStrategy waitStrategy,
BlockStrategy blockStrategy,
com.google.common.base.Predicate<Attempt<V>> rejectionPredicate,
Collection<RetryListener> listeners)
Constructor
|
Retryer(AttemptTimeLimiter<V> attemptTimeLimiter,
StopStrategy stopStrategy,
WaitStrategy waitStrategy,
com.google.common.base.Predicate<Attempt<V>> rejectionPredicate)
Constructor
|
Retryer(StopStrategy stopStrategy,
WaitStrategy waitStrategy,
com.google.common.base.Predicate<Attempt<V>> rejectionPredicate)
Constructor
|
public Retryer(@Nonnull StopStrategy stopStrategy, @Nonnull WaitStrategy waitStrategy, @Nonnull com.google.common.base.Predicate<Attempt<V>> rejectionPredicate)
stopStrategy - the strategy used to decide when the retryer must stop retryingwaitStrategy - the strategy used to decide how much time to sleep between attemptsrejectionPredicate - the predicate used to decide if the attempt must be rejected
or not. If an attempt is rejected, the retryer will retry the call, unless the stop
strategy indicates otherwise or the thread is interrupted.public Retryer(@Nonnull AttemptTimeLimiter<V> attemptTimeLimiter, @Nonnull StopStrategy stopStrategy, @Nonnull WaitStrategy waitStrategy, @Nonnull com.google.common.base.Predicate<Attempt<V>> rejectionPredicate)
attemptTimeLimiter - to prevent from any single attempt from spinning infinitelystopStrategy - the strategy used to decide when the retryer must stop retryingwaitStrategy - the strategy used to decide how much time to sleep between attemptsrejectionPredicate - the predicate used to decide if the attempt must be rejected
or not. If an attempt is rejected, the retryer will retry the call, unless the stop
strategy indicates otherwise or the thread is interrupted.public Retryer(@Nonnull AttemptTimeLimiter<V> attemptTimeLimiter, @Nonnull StopStrategy stopStrategy, @Nonnull WaitStrategy waitStrategy, @Nonnull BlockStrategy blockStrategy, @Nonnull com.google.common.base.Predicate<Attempt<V>> rejectionPredicate)
attemptTimeLimiter - to prevent from any single attempt from spinning infinitelystopStrategy - the strategy used to decide when the retryer must stop retryingwaitStrategy - the strategy used to decide how much time to sleep between attemptsblockStrategy - the strategy used to decide how to block between retry attempts; eg, Thread#sleep(), latches, etc.rejectionPredicate - the predicate used to decide if the attempt must be rejected
or not. If an attempt is rejected, the retryer will retry the call, unless the stop
strategy indicates otherwise or the thread is interrupted.@Beta public Retryer(@Nonnull AttemptTimeLimiter<V> attemptTimeLimiter, @Nonnull StopStrategy stopStrategy, @Nonnull WaitStrategy waitStrategy, @Nonnull BlockStrategy blockStrategy, @Nonnull com.google.common.base.Predicate<Attempt<V>> rejectionPredicate, @Nonnull Collection<RetryListener> listeners)
attemptTimeLimiter - to prevent from any single attempt from spinning infinitelystopStrategy - the strategy used to decide when the retryer must stop retryingwaitStrategy - the strategy used to decide how much time to sleep between attemptsblockStrategy - the strategy used to decide how to block between retry attempts; eg, Thread#sleep(), latches, etc.rejectionPredicate - the predicate used to decide if the attempt must be rejected
or not. If an attempt is rejected, the retryer will retry the call, unless the stop
strategy indicates otherwise or the thread is interrupted.listeners - collection of retry listenerspublic V call(Callable<V> callable) throws ExecutionException, RetryException
callable - the callable task to be executedExecutionException - if the given callable throws an exception, and the
rejection predicate considers the attempt as successful. The original exception
is wrapped into an ExecutionException.RetryException - if all the attempts failed before the stop strategy decided
to abort, or the thread was interrupted. Note that if the thread is interrupted,
this exception is thrown and the thread's interrupt status is set.public Retryer.RetryerCallable<V> wrap(Callable<V> callable)
Callable in a Retryer.RetryerCallable, which can
be submitted to an executor. The returned Retryer.RetryerCallable uses
this Retryer instance to call the given Callable.callable - the callable to wrapRetryer.RetryerCallable that behaves like the given Callable with retry behavior defined by this RetryerCopyright © 2023. All rights reserved.