Package org.jppf.utils
Class RetryUtils
java.lang.Object
org.jppf.utils.RetryUtils
Utility methods for retrying a callback that throws an exception, until it succeeds or
either a maximum number of attempts is reached or a timeout expires.
- Since:
- 6.0
- Author:
- Laurent Cohen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TrunWithRetry(int maxTries, long retryDelay, Callable<T> callable) Execute the specifiedCallablein a retry loop.static <T> TrunWithRetryTimeout(long timeout, long retryDelay, Runnable runnable) Execute the specifiedRunnablein a retry loop.static <T> TrunWithRetryTimeout(long timeout, long retryDelay, Callable<T> callable) Execute the specifiedCallablein a retry loop.
-
Constructor Details
-
RetryUtils
public RetryUtils()
-
-
Method Details
-
runWithRetry
public static <T> T runWithRetry(int maxTries, long retryDelay, Callable<T> callable) throws Exception Execute the specifiedCallablein a retry loop.- Type Parameters:
T- the return type of theCallable.- Parameters:
maxTries- the maximum number of attempts to execute theCallable.retryDelay- the delay between two attempts.callable- theCallableto execute.- Returns:
- the return value of the first successful execution of the
Callable. - Throws:
Exception- if after maxRetries theCallablethrew an exception.
-
runWithRetryTimeout
public static <T> T runWithRetryTimeout(long timeout, long retryDelay, Callable<T> callable) throws Exception Execute the specifiedCallablein a retry loop.- Type Parameters:
T- the return type of theCallable.- Parameters:
timeout- the maximum tim during which to attempt, in millis.retryDelay- the delay between two attempts.callable- theCallableto execute.- Returns:
- the return value of the first successful execution of the
Callable. - Throws:
Exception- if after maxRetries theCallablethrew an exception.
-
runWithRetryTimeout
public static <T> T runWithRetryTimeout(long timeout, long retryDelay, Runnable runnable) throws Exception Execute the specifiedRunnablein a retry loop.- Type Parameters:
T- the return type of theCallable.- Parameters:
timeout- the maximum tim during which to attempt, in millis.retryDelay- the delay between two attempts.runnable- theRunnableto execute.- Returns:
- the return value of the first successful execution of the
Callable. - Throws:
Exception- if after maxRetries theCallablethrew an exception.
-