Class RetryUtils
-
- All Implemented Interfaces:
public final class RetryUtilsUtility class for retrying actions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classRetryUtils.RetryPolicyThis class encapsulates a retry policy.
-
Field Summary
Fields Modifier and Type Field Description public final static RetryUtils.RetryPolicyDEFAULT_RETRY_POLICY
-
Method Summary
Modifier and Type Method Description static RetryUtils.RetryPolicy.BuilderretryPolicyBuilder()This method returns a RetryPolicy.Builder. static <T> TwithRetry(Callable<T> action)This method attempts to execute a given action up to a specified number of times with a 1-second delay. static <T> TwithRetry(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. static <T> TwithRetryMappingExceptions(Callable<T> action)This method attempts to execute a given action up to a specified number of times with a 1-second delay. static <T> TwithRetryMappingExceptions(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. static <T> TwithRetryMappingExceptions(Callable<T> action, int maxAttempts, ExceptionMapper exceptionMapper)This method attempts to execute a given action up to a specified number of times with a 1-second delay. -
-
Method Detail
-
retryPolicyBuilder
static RetryUtils.RetryPolicy.Builder retryPolicyBuilder()
This method returns a RetryPolicy.Builder.
- Returns:
A RetryPolicy.Builder.
-
withRetry
static <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
static <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.
-
withRetryMappingExceptions
static <T> T withRetryMappingExceptions(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, the Exception causing the failure will be mapped with the default ExceptionMapper.
- Parameters:
action- The action to be executed.- Returns:
The result of the action if it is successful.
-
withRetryMappingExceptions
static <T> T withRetryMappingExceptions(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, the Exception causing the failure will be mapped with the default ExceptionMapper.
- 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.
-
withRetryMappingExceptions
static <T> T withRetryMappingExceptions(Callable<T> action, int maxAttempts, ExceptionMapper exceptionMapper)
This method attempts to execute a given action up to a specified number of times with a 1-second delay. If the action fails, the Exception causing the failure will be mapped with the provided ExceptionMapper.
- Parameters:
action- The action to be executed.maxAttempts- The maximum number of attempts to execute the action.exceptionMapper- The ExceptionMapper used to translate the exception that caused the failure of the action invocation.- Returns:
The result of the action if it is successful.
-
-
-
-