Package com.nike.pdm.localstack.core
Class Retry
- java.lang.Object
-
- com.nike.pdm.localstack.core.Retry
-
public final class Retry extends java.lang.Object
Wrapper function that retries, with exponential backoff, in the event of an exception.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Retry.RetryableFunction<T>
Function that adds retries with exponential backoff.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_RETRIES
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
execute(Retry.RetryableFunction<T> fn)
Executes the wrapped function with default maximum number of retries in the event of an exception.static <T> T
execute(Retry.RetryableFunction<T> fn, int maxRetries)
Executes the wrapped function with the specified maximum number of retries in the event of an exception.static <T> T
execute(Retry.RetryableFunction<T> fn, int maxRetries, java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> expectedErrors)
Executes the wrapped function, terminating immediately if one of the expected errors is encountered, otherwise the function will be retried up to the specified maximum number of retries.static <T> T
execute(Retry.RetryableFunction<T> fn, java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> expectedErrors)
Executes the wrapped function, terminating immediately if one of the expected errors is encountered.
-
-
-
Field Detail
-
DEFAULT_MAX_RETRIES
public static final int DEFAULT_MAX_RETRIES
- See Also:
- Constant Field Values
-
-
Method Detail
-
execute
public static <T> T execute(Retry.RetryableFunction<T> fn)
Executes the wrapped function with default maximum number of retries in the event of an exception.- Type Parameters:
T
- return type of the wrapped function- Parameters:
fn
- wrapped function to execute- Returns:
- result of the wrapped function
-
execute
public static <T> T execute(Retry.RetryableFunction<T> fn, int maxRetries)
Executes the wrapped function with the specified maximum number of retries in the event of an exception.- Type Parameters:
T
- return type of the wrapped function- Parameters:
fn
- wrapped function to executemaxRetries
- maximum number of times to retry the wrapped function in the event of an exception- Returns:
- result of the wrapped function
-
execute
public static <T> T execute(Retry.RetryableFunction<T> fn, java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> expectedErrors)
Executes the wrapped function, terminating immediately if one of the expected errors is encountered.- Type Parameters:
T
- return type of the wrapped function- Parameters:
fn
- wrapped function to executeexpectedErrors
- a collection of errors that when encountered will cause the function to fail immediately without exhausting the maximum number of retries- Returns:
- result of the wrapped function
-
execute
public static <T> T execute(Retry.RetryableFunction<T> fn, int maxRetries, java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> expectedErrors)
Executes the wrapped function, terminating immediately if one of the expected errors is encountered, otherwise the function will be retried up to the specified maximum number of retries.- Type Parameters:
T
- return type of the wrapped function- Parameters:
fn
- wrapped function to executemaxRetries
- maximum number of times to retry the wrapped function in the event of an exception not specified in the expectedErrorsexpectedErrors
- a collection of errors that when encountered will cause the function to fail immediately without exhausting the maximum number of retries- Returns:
- result of the wrapped function
-
-