Package com.helixframework.retry
Class FixedRetry
java.lang.Object
com.helixframework.retry.FixedRetry
Wrapper function that retries with fixed delay in the event of an exception.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationDefault delay between retry attempts.static final DurationDefault initial delay before retry is attempted.static final intDefault number of retries attempted by this function before throwingRetriesExhaustedException. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Texecute(RetryableFunction<T> fn) Executes a retryable function.static <T> Texecute(RetryableFunction<T> fn, int maxRetries) Executes a retryable function with a specified maximum number of retries.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Duration delay) Executes a retryable function with a specified maximum number of retries and delay duration.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay) Executes a retryable function with a specified maximum number of retries, delay, and initial delay.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Collection<Class<? extends Throwable>> expectedErrors) Executes a retryable function with the specified parameters.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Supplier<T> fallback) Executes a function with retry logic to handle expected errors.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Supplier<T> fallback, Collection<Class<? extends Throwable>> expectedErrors) Executes a function with retry logic to handle expected errors.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Duration delay, Collection<Class<? extends Throwable>> expectedErrors) Executes a retryable function with a specified maximum number of retries, delay, and expected errors that will not trigger a retry.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Duration delay, Supplier<T> fallback) Executes a function with retry logic to handle expected errors.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Collection<Class<? extends Throwable>> expectedErrors) Executes a retryable function with a specified maximum number of retries, delay, initial delay, and expected errors that will not trigger a retry.static <T> Texecute(RetryableFunction<T> fn, int maxRetries, Supplier<T> fallback) Executes a function with retry logic to handle expected errors.static <T> Texecute(RetryableFunction<T> fn, Collection<Class<? extends Throwable>> expectedErrors) Executes a retryable function with a collection of expected errors that will not trigger a retry.static <T> Texecute(RetryableFunction<T> fn, Supplier<T> fallback) Executes a function with retry logic to handle expected errors.
-
Field Details
-
DEFAULT_MAX_RETRIES
public static final int DEFAULT_MAX_RETRIESDefault number of retries attempted by this function before throwingRetriesExhaustedException.- See Also:
-
DEFAULT_INITIAL_DELAY
Default initial delay before retry is attempted. Defaults to 1 second. -
DEFAULT_DELAY
Default delay between retry attempts. Defaults to 1 second.
-
-
Method Details
-
execute
Executes a retryable function.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to execute- Returns:
- the result of the retryable function
- Throws:
RetriesExhaustedException- if the maximum number of retries is exhausted
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries) throws RetriesExhaustedException Executes a retryable function with a specified maximum number of retries.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retries- Returns:
- the result of the retryable function
- Throws:
RetriesExhaustedException- if the maximum number of retries is exhausted
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay) throws RetriesExhaustedException Executes a retryable function with a specified maximum number of retries and delay duration.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retriesdelay- the delay between retries- Returns:
- the result of the retryable function
- Throws:
RetriesExhaustedException- if the maximum number of retries is exhausted
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay) throws RetriesExhaustedException Executes a retryable function with a specified maximum number of retries, delay, and initial delay.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retriesdelay- the delay between retriesinitialDelay- the initial delay before the first retry- Returns:
- the result of the retryable function
- Throws:
RetriesExhaustedException- if the maximum number of retries is exhausted
-
execute
public static <T> T execute(RetryableFunction<T> fn, Collection<Class<? extends Throwable>> expectedErrors) throws RetriesExhaustedException Executes a retryable function with a collection of expected errors that will not trigger a retry.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executeexpectedErrors- a collection of expected error classes that will not trigger a retry- Returns:
- the result of the retryable function
- Throws:
RetriesExhaustedException- if the maximum number of retries is exhausted
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Collection<Class<? extends Throwable>> expectedErrors) throws RetriesExhaustedException Executes a retryable function with a specified maximum number of retries, delay, initial delay, and expected errors that will not trigger a retry.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retriesexpectedErrors- a collection of expected error classes that will not trigger a retry- Returns:
- the result of the retryable function
- Throws:
RetriesExhaustedException- if the maximum number of retries is exhaustedIllegalArgumentException- if maxRetries is negative, delay or initialDelay is null or negative
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Collection<Class<? extends Throwable>> expectedErrors) throws RetriesExhaustedException Executes a retryable function with a specified maximum number of retries, delay, and expected errors that will not trigger a retry.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retriesdelay- the delay between retriesexpectedErrors- a collection of expected error classes that will not trigger a retry- Returns:
- the result of the retryable function
- Throws:
RetriesExhaustedException- if the maximum number of retries is exhaustedIllegalArgumentException- if maxRetries is negative, delay or initialDelay is null or negative
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Collection<Class<? extends Throwable>> expectedErrors) throws RetriesExhaustedException Executes a retryable function with the specified parameters.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retriesdelay- the delay between retriesinitialDelay- the initial delay before the first retryexpectedErrors- a collection of expected error classes that will not trigger a retry- Returns:
- the result of the retryable function
- Throws:
RetriesExhaustedException- if the maximum number of retries is exhaustedIllegalArgumentException- if maxRetries is negative, delay or initialDelay is null or negative, or expectedErrors is null
-
execute
Executes a function with retry logic to handle expected errors.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executefallback- the supplier that provides a fallback value- Returns:
- the result of the retryable function or the fallback value
-
execute
Executes a function with retry logic to handle expected errors.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retriesfallback- the supplier that provides a fallback value- Returns:
- the result of the retryable function or the fallback value
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Supplier<T> fallback) Executes a function with retry logic to handle expected errors.- Type Parameters:
T- the return type of the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retriesdelay- the delay between retriesfallback- the supplier that provides a fallback value- Returns:
- the result of the retryable function
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Supplier<T> fallback) Executes a function with retry logic to handle expected errors.- Type Parameters:
T- the type of the value returned by the retryable function- Parameters:
fn- the retryable function to executemaxRetries- the maximum number of retries to attempt if the function fails (non-negative integer)delay- the delay between retries (positive duration)initialDelay- the initial delay before the first retry (non-negative duration)fallback- the supplier to provide a fallback value if all retries fail- Returns:
- the value returned by the retryable function if it succeeds, or the fallback value if all retries fail
-
execute
public static <T> T execute(RetryableFunction<T> fn, int maxRetries, Duration delay, Duration initialDelay, Supplier<T> fallback, Collection<Class<? extends Throwable>> expectedErrors) Executes a function with retry logic to handle expected errors.- Type Parameters:
T- The return type of the function.- Parameters:
fn- The retryable function to execute.maxRetries- The maximum number of retries allowed.delay- The delay between each retry attempt.initialDelay- The initial delay before the first retry attempt.fallback- The fallback supplier to be called when all retries are exhausted.expectedErrors- The collection of expected error classes that should trigger a retry.- Returns:
- The result of the function execution
-