/** * Executes a {@link Runnable}, retrying if it throws something retryable. * * @param runnable the runnable to run * @param retryStrategy the retry strategy to use if the callable fails in a retryable way * @param isRetryable predicate to determine whether the callable failure is retryable or not * @param <T> the type of throwable * @throws InterruptedException if the call was interrupted between retries. The last Throwable that triggered the * retry will be added as a suppressed exception. * @throws T if the callable failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. */ public static <T extends Throwable> void runWithInterruptibleRetries(Runnable<T> runnable, RetryStrategy retryStrategy, Predicate<Throwable> isRetryable) throws T, InterruptedException { callWithInterruptibleRetries((Callable<Void, T>) () -> { runnable.run(); return null; }, retryStrategy, isRetryable); }
/** * Executes a {@link Runnable}, retrying if it throws something retryable. * * @param runnable the runnable to run * @param retryStrategy the retry strategy to use if the callable fails in a retryable way * @param isRetryable predicate to determine whether the callable failure is retryable or not * @param <T> the type of throwable * @throws InterruptedException if the call was interrupted between retries. The last Throwable that triggered the * retry will be added as a suppressed exception. * @throws T if the callable failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. */ public static <T extends Throwable> void runWithInterruptibleRetries(Runnable<T> runnable, RetryStrategy retryStrategy, Predicate<Throwable> isRetryable) throws T, InterruptedException { callWithInterruptibleRetries((Callable<Void, T>) () -> { runnable.run(); return null; }, retryStrategy, isRetryable); }
/** * Executes {@link Runnable#run()}, retrying the call if it throws something retryable. * * @param runnable the callable to run * @param retryStrategy the retry strategy to use if the supplier fails in a retryable way * @param isRetryable predicate to determine whether the supplier failure is retryable or not * @param <T> the type of throwable * @throws T if the runnable failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. * If the call was interrupted while waiting between retries, the {@link InterruptedException} will be added * as a suppressed exception */ public static <T extends Throwable> void runWithRetries(Runnable<T> runnable, RetryStrategy retryStrategy, Predicate<Throwable> isRetryable) throws T { callWithRetries((Callable<Void, T>) () -> { runnable.run(); return null; }, retryStrategy, isRetryable); }
/** * Executes {@link Runnable#run()}, retrying the call if it throws something retryable. * * @param runnable the callable to run * @param retryStrategy the retry strategy to use if the supplier fails in a retryable way * @param isRetryable predicate to determine whether the supplier failure is retryable or not * @param <T> the type of throwable * @throws T if the runnable failed in a way that is not retryable, or the retries were exhausted. * If retries were exhausted, a {@link RetriesExhaustedException} will be added as a suppressed exception. * If the call was interrupted while waiting between retries, the {@link InterruptedException} will be added * as a suppressed exception */ public static <T extends Throwable> void runWithRetries(Runnable<T> runnable, RetryStrategy retryStrategy, Predicate<Throwable> isRetryable) throws T { callWithRetries((Callable<Void, T>) () -> { runnable.run(); return null; }, retryStrategy, isRetryable); }