public static final class RetryUtils.RetryPolicy extends Object
Modifier and Type | Class and Description |
---|---|
static class |
RetryUtils.RetryPolicy.Builder
This class encapsulates a retry policy builder.
|
Constructor and Description |
---|
RetryPolicy(int maxAttempts,
int delayMillis,
double jitterScale,
double backoffExp)
Construct a RetryPolicy.
|
Modifier and Type | Method and Description |
---|---|
int |
jitterDelayMillis(int attempt)
This method returns the jitter delay in milliseconds for a given attempt.
|
double |
rawDelayMs(int attempt)
This method returns the raw delay in milliseconds for a given attempt.
|
void |
sleep(int attempt)
This method sleeps for a given attempt.
|
<T> T |
withRetry(Callable<T> action)
This method attempts to execute a given action up to a specified number of times with a 1-second delay.
|
<T> T |
withRetry(Callable<T> action,
int maxAttempts)
This method attempts to execute a given action up to a specified number of times with a 1-second delay.
|
public RetryPolicy(int maxAttempts, int delayMillis, double jitterScale, double backoffExp)
maxAttempts
- The maximum number of attempts.delayMillis
- The delay in milliseconds.jitterScale
- The jitter scale.backoffExp
- The backoff exponent.public double rawDelayMs(int attempt)
attempt
- The attempt number.public int jitterDelayMillis(int attempt)
attempt
- The attempt number.public void sleep(int attempt)
attempt
- The attempt number.public <T> T withRetry(Callable<T> action)
T
- The type of the result of the action.action
- The action to be executed.RuntimeException
- if the action fails on all attempts.public <T> T withRetry(Callable<T> action, int maxAttempts)
T
- The type of the result of the action.action
- The action to be executed.maxAttempts
- The maximum number of attempts to execute the action.RuntimeException
- if the action fails on all attempts.Copyright © 2024. All rights reserved.