V
- the type of the call return valuepublic final class Retryer<V>
extends java.lang.Object
RetryerBuilder
. A retryer
is thread-safe, provided the arguments passed to its constructor are thread-safe.Modifier and Type | Class and Description |
---|---|
static class |
Retryer.RetryerCallable<X>
A
Callable which wraps another Callable in order to add
retrying behavior from a given Retryer instance. |
Constructor and Description |
---|
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,
java.util.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
|
Modifier and Type | Method and Description |
---|---|
V |
call(java.util.concurrent.Callable<V> callable)
Executes the given callable.
|
Retryer.RetryerCallable<V> |
wrap(java.util.concurrent.Callable<V> callable)
Wraps the given
Callable in a Retryer.RetryerCallable , which can
be submitted to an executor. |
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 java.util.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(java.util.concurrent.Callable<V> callable) throws java.util.concurrent.ExecutionException, RetryException
callable
- the callable task to be executedjava.util.concurrent.ExecutionException
- 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(java.util.concurrent.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 Retryer