V
- the type of the call return valuepublic final class Retryer<V>
extends java.lang.Object
A retryer can also wrap the callable into a RetryerCallable, which can be submitted to an executor.
Retryer instances are better constructed with a 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 make it call by the enclosing retryer.
|
Constructor and Description |
---|
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 into 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 V call(java.util.concurrent.Callable<V> callable) throws java.util.concurrent.ExecutionException, RetryException
java.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)
Retryer.RetryerCallable
, which can be submitted to an executor.
The returned callable will use this retryer to call the given callablecallable
- the callable to wrap