Interface Retryer
public interface Retryer
-
Method Summary
Modifier and TypeMethodDescription<T> TExecutes aCallablewith the context of the retry.<T> Tget(Callable<T> callable, Consumer<SuccessfulAttempt> successfulAttemptConsumer, Consumer<FailedAttempt> failedAttemptConsumer) Executes aCallablewith the context of the retry.voidrun(CheckedRunnable runnable) Executes aCheckedRunnablewith the context of the retry.voidrun(CheckedRunnable runnable, Consumer<SuccessfulAttempt> successfulAttemptConsumer, Consumer<FailedAttempt> failedAttemptConsumer) Executes aCheckedRunnablewith the context of the retry.<T> RetryerwithRetryIf(Predicate<T> predicate) Optional predicates to be compared against the result of the "get" result of a retry.withRetryOn(Predicate<Throwable> throwablePredicate) Optional predicates to be evaluated before the retryer implementation runs a retry
-
Method Details
-
get
Executes aCallablewith the context of the retry. If the callable throws any exception, then the retryer will handle that according with the configuration the retryer was created. -
run
Executes aCheckedRunnablewith the context of the retry. If theCheckedRunnablethrows any exception, then the retryer will handle that according with the configuration the retryer was created.- Parameters:
runnable-CheckedRunnableto be executed
-
get
<T> T get(Callable<T> callable, Consumer<SuccessfulAttempt> successfulAttemptConsumer, Consumer<FailedAttempt> failedAttemptConsumer) Executes aCallablewith the context of the retry. If the callable throws any exception, then the retryer will handle that according with the configuration the retryer was created. This override provides consumer handlers that will allow you to create custom actions on each failure or successful attempt.- Type Parameters:
T- type returned by providedCallable- Parameters:
callable-Callableto be executedsuccessfulAttemptConsumer- Consumer that accepts theSuccessfulAttempt, if there was one. This object contains context information such as "what retry did this succeed on?".failedAttemptConsumer- Consumer that accepts aFailedAttemptthat provides retry context information such as error message.- Returns:
- the output from the callable
-
run
void run(CheckedRunnable runnable, Consumer<SuccessfulAttempt> successfulAttemptConsumer, Consumer<FailedAttempt> failedAttemptConsumer) Executes aCheckedRunnablewith the context of the retry. If theCheckedRunnablethrows any exception, then the retryer will handle that according with the configuration the retryer was created. This override provides consumer handlers that will allow you to create custom actions on each failure or successful attempt.- Parameters:
runnable-CheckedRunnableto be executedsuccessfulAttemptConsumer- Consumer that accepts theSuccessfulAttempt, if there was one. This object contains context information such as "what retry did this succeed on?".failedAttemptConsumer- Consumer that accepts aFailedAttemptthat provides retry context information such as error message.
-
withRetryOn
Optional predicates to be evaluated before the retryer implementation runs a retry- Parameters:
throwablePredicate- Predicate to verify against the exceptions thrown on the retry.- Returns:
- current retryer, altered
-
withRetryIf
Optional predicates to be compared against the result of the "get" result of a retry. If it matches, will try again.- Type Parameters:
T- type accepted by predicate- Parameters:
predicate- Predicate to verify against the result of the retry.- Returns:
- current retryer, altered
-