Module kivakit.core

Class Retry

All Implemented Interfaces:
Broadcaster, Listener, Repeater, Transceiver, Receiver, Transmitter, NamedObject

public class Retry extends BaseRepeater
Retry running a Runnable
Author:
matthieun, jonathanl
  • Field Details

    • MAXIMUM_NUMBER_RETRIES

      public static final int MAXIMUM_NUMBER_RETRIES
      See Also:
  • Constructor Details

    • Retry

      public Retry(Listener listener)
      A basic Retry that does not wait before retrying and catches all Throwable errors.
    • Retry

      public Retry(Listener listener, int numberOfRetries, Duration retryWaitDuration, Class<? extends Throwable> exceptionType, String... exceptionMessageExclusion)
      A retry tool to run a Runnable as long as there is one type of exception
      Parameters:
      listener - Listener for the broadcasts
      numberOfRetries - The number of failures allowed
      retryWaitDuration - The duration to wait between retries
      exceptionType - The type of exception to be caught. It needs to be a type that extends Throwable
      exceptionMessageExclusion - An arbitrary number of Strings. If the exception caught has a message that contains one of the Strings contained in this set, the exception will be thrown and no retry will be made.
  • Method Details

    • retry

      public static <T> UncheckedCode<T> retry(UncheckedCode<T> code, int times, Duration delay, Runnable... beforeRetry)
    • run

      public <T> T run(UncheckedCode<T> runnable, Runnable... stepsBeforeRetry)
      Run a Runnable and retry as long as the exception type defined is thrown
      Parameters:
      runnable - The runnable to be tried
      stepsBeforeRetry - This is an optional list of steps executed in case the try fails, and right before each retry