Class RetryUtils.RetryPolicy
-
- All Implemented Interfaces:
public final class RetryUtils.RetryPolicy
This class encapsulates a retry policy.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final class
RetryUtils.RetryPolicy.Builder
This class encapsulates a retry policy builder.
-
Constructor Summary
Constructors Constructor Description RetryUtils.RetryPolicy(int maxAttempts, int delayMillis, double jitterScale, double backoffExp)
Construct a RetryPolicy.
-
Method Summary
Modifier and Type Method Description double
rawDelayMs(int attempt)
This method returns the raw delay in milliseconds for a given attempt. int
jitterDelayMillis(int attempt)
This method returns the jitter 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. -
-
Constructor Detail
-
RetryUtils.RetryPolicy
RetryUtils.RetryPolicy(int maxAttempts, int delayMillis, double jitterScale, double backoffExp)
Construct a RetryPolicy.- Parameters:
maxAttempts
- The maximum number of attempts.delayMillis
- The delay in milliseconds.jitterScale
- The jitter scale.backoffExp
- The backoff exponent.
-
-
Method Detail
-
rawDelayMs
double rawDelayMs(int attempt)
This method returns the raw delay in milliseconds for a given attempt.
- Parameters:
attempt
- The attempt number.- Returns:
The raw delay in milliseconds.
-
jitterDelayMillis
int jitterDelayMillis(int attempt)
This method returns the jitter delay in milliseconds for a given attempt.
- Parameters:
attempt
- The attempt number.- Returns:
The jitter delay in milliseconds.
-
sleep
void sleep(int attempt)
This method sleeps for a given attempt.
- Parameters:
attempt
- The attempt number.
-
withRetry
<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. If the action fails on all attempts, it throws a RuntimeException.
- Parameters:
action
- The action to be executed.- Returns:
The result of the action if it is successful.
-
withRetry
<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. If the action fails on all attempts, it throws a RuntimeException.
- Parameters:
action
- The action to be executed.maxAttempts
- The maximum number of attempts to execute the action.- Returns:
The result of the action if it is successful.
-
-
-
-