Package io.atlassian.fugue.retry
Class RetrySupplier<T>
- java.lang.Object
-
- io.atlassian.fugue.retry.RetrySupplier<T>
-
- Type Parameters:
T- The type of the result the Supplier yields upon application
- All Implemented Interfaces:
java.util.function.Supplier<T>
public class RetrySupplier<T> extends java.lang.Object implements java.util.function.Supplier<T>A Supplier which wraps the apply method of another Supplier 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 ExceptionHandlerhandlerprivate java.util.function.Supplier<T>supplierprivate inttries
-
Constructor Summary
Constructors Constructor Description RetrySupplier(java.util.function.Supplier<T> supplier, int tries)An instance that does nothing before retrying and ignores exceptions that occur.RetrySupplier(java.util.function.Supplier<T> supplier, int tries, ExceptionHandler handler)An instance that does nothing before retrying.RetrySupplier(java.util.function.Supplier<T> supplier, int tries, ExceptionHandler handler, java.lang.Runnable beforeRetry)Constructor for RetrySupplier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tget()Attempt to get a result tries number of times.
-
-
-
Field Detail
-
supplier
private final java.util.function.Supplier<T> supplier
-
tries
private final int tries
-
handler
private final ExceptionHandler handler
-
beforeRetry
private final java.lang.Runnable beforeRetry
-
-
Constructor Detail
-
RetrySupplier
public RetrySupplier(java.util.function.Supplier<T> supplier, int tries)
An instance that does nothing before retrying and ignores exceptions that occur.- Parameters:
supplier- which fetches the result, must not be nulltries- the number of times to attempt to get a result, must be positive
-
RetrySupplier
public RetrySupplier(java.util.function.Supplier<T> supplier, int tries, ExceptionHandler handler)
An instance that does nothing before retrying.- Parameters:
supplier- 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
-
RetrySupplier
public RetrySupplier(java.util.function.Supplier<T> supplier, int tries, ExceptionHandler handler, java.lang.Runnable beforeRetry)
Constructor for RetrySupplier.
- Parameters:
supplier- 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- a task which will run at the end of any
-
-
Method Detail
-
get
public T get()
Attempt to get a result 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.- Specified by:
getin interfacejava.util.function.Supplier<T>
-
-