Package io.atlassian.fugue.retry
Class RetryFunction<F,T>
- java.lang.Object
-
- io.atlassian.fugue.retry.RetryFunction<F,T>
-
- Type Parameters:
F- The type of the parameter the Function acceptsT- The type of the result the Function yields upon application
- All Implemented Interfaces:
java.util.function.Function<F,T>
public class RetryFunction<F,T> extends java.lang.Object implements java.util.function.Function<F,T>A Function which wraps the apply method of another Function and attempts it up to a fixed number of times. This class can be used when a task is known to be prone to occasional failure and other workarounds are not known.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.RunnablebeforeRetryprivate java.util.function.Function<F,T>functionprivate ExceptionHandlerhandlerprivate inttries
-
Constructor Summary
Constructors Constructor Description RetryFunction(java.util.function.Function<F,T> function, int tries)An instance that does nothing before retrying and ignores exceptions that occur.RetryFunction(java.util.function.Function<F,T> function, int tries, ExceptionHandler handler)An instance that does nothing before retrying.RetryFunction(java.util.function.Function<F,T> function, int tries, ExceptionHandler handler, java.lang.Runnable beforeRetry)Constructor for RetryFunction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tapply(F parameter)Attempt to apply parameter to the wrapped Function tries number of times.
-
-
-
Field Detail
-
tries
private final int tries
-
handler
private final ExceptionHandler handler
-
beforeRetry
private final java.lang.Runnable beforeRetry
-
-
Constructor Detail
-
RetryFunction
public RetryFunction(java.util.function.Function<F,T> function, int tries)
An instance that does nothing before retrying and ignores exceptions that occur.- Parameters:
function- which fetches the result, must not be nulltries- the numbe rof times to attempt to get a result, must be positive
-
RetryFunction
public RetryFunction(java.util.function.Function<F,T> function, int tries, ExceptionHandler handler)
An instance that does nothing before retrying.- Parameters:
function- which fetches the result, must not be nulltries- the number of times to attempt to get a result, must be positivehandler- reacts to exceptions thrown by the supplier, must not be null
-
RetryFunction
public RetryFunction(java.util.function.Function<F,T> function, int tries, ExceptionHandler handler, java.lang.Runnable beforeRetry)
Constructor for RetryFunction.
- Parameters:
function- which fetches the result, must not be nulltries- the number of times to attempt to get a result, must be positivehandler- reacts to exceptions thrown by the supplier, must not be nullbeforeRetry- an effect that is run before a retry attempt
-
-
Method Detail
-
apply
public T apply(F parameter)
Attempt to apply parameter to the wrapped Function tries number of times. Any exceptions thrown will be ignored until the number of attempts is reached. If the number of attempts is reached without a successful result, the most recent exception to be thrown will be rethrown.
-
-