public abstract class RetryPolicy extends Object implements Serializable
The retryOn(Exception) method specifies the exception conditions of
when a retry should occur.
The run(Retryable) method is the entrypoint for a Retryable
object to be executed.
| Constructor and Description |
|---|
RetryPolicy(int maxRetries,
double jitter)
Creates a new
RetryPolicy with the specified maxRetries
value. |
| Modifier and Type | Method and Description |
|---|---|
abstract long |
getDelayMs(int attemptNo)
Returns the delay in milliseconds for the specified attempt number.
|
int |
getMaxRetries()
Returns the number of retry attempts allowed by this
RetryPolicy. |
protected boolean |
retryOn(Exception e)
Specifies the exception conditions of when a retry should occur.
|
<T> T |
run(Retryable<T> retryable)
The entrypoint for a
Retryable object to be executed. |
<T> T |
run(Retryable<T> retryable,
long timeout)
The entrypoint for a
Retryable object to be executed. |
public RetryPolicy(int maxRetries,
double jitter)
RetryPolicy with the specified maxRetries
value.maxRetries - A positive value representing the number of retry
attempts allowed by the RetryPolicy.jitter - The factor multiplier to be applied to
getDelayMs(int) to thereafter be added to the delay for
each retry.IllegalArgumentException - If maxRetries or jitter is
negative.protected boolean retryOn(Exception e)
e - The exception that occurred during execution of a
Retryable object.true if a retry should occur, otherwise false.public final <T> T run(Retryable<T> retryable) throws RetryFailureException
Retryable object to be executed. Exceptions in
Retryable.retry(RetryPolicy,int) will be considered for retry if
the number of maxRetries has not been exceeded, and
retryOn(Exception) returns true.T - The type of the result object.retryable - The Retryable object to run.Retryable.retry(RetryPolicy,int).RetryFailureException - If retry attempts have exceeded
maxRetries, or if retryOn(Exception) returns
false.NullPointerException - If retryable is null.public final <T> T run(Retryable<T> retryable, long timeout) throws RetryFailureException
Retryable object to be executed. Exceptions in
Retryable.retry(RetryPolicy,int) will be considered for retry if
the number of maxRetries has not been exceeded, and
retryOn(Exception) returns true.T - The type of the result object.retryable - The Retryable object to run.timeout - The maximum time to retry in milliseconds.Retryable.retry(RetryPolicy,int).RetryFailureException - If retry attempts have exceeded
maxRetries, if retryOn(Exception) returns
false, or if timeout is exceeded.IllegalArgumentException - If timeout is negative.NullPointerException - If the value of timeout is negative.public int getMaxRetries()
RetryPolicy.RetryPolicy.public abstract long getDelayMs(int attemptNo)
attemptNo - The attempt number, starting with 1.Copyright © 2020 LightStep. All rights reserved.