Class Retrier


  • public class Retrier
    extends Object
    Handles performing actions that need to be retried. Expected usage example (using lambda): Retrier retrier = new Retrier(); return retrier.execute(() -> { // The actual method being executed return doWork(); }); Older style usage, this is equivalent to the above example: Retrier retrier = new Retrier(); return retrier.execute(new Retriable() {
    Author:
    Bill Branan Date: 10/23/13
    • Field Detail

      • DEFAULT_MAX_RETRIES

        public static final int DEFAULT_MAX_RETRIES
        Default max number of attempts to make in performing a Retriable action
        See Also:
        Constant Field Values
      • DEFAULT_WAIT_BETWEEN_RETRIES

        public static final int DEFAULT_WAIT_BETWEEN_RETRIES
        See Also:
        Constant Field Values
      • DEFAULT_WAIT_MULTIPLIER

        public static final int DEFAULT_WAIT_MULTIPLIER
        See Also:
        Constant Field Values
    • Constructor Detail

      • Retrier

        public Retrier()
      • Retrier

        public Retrier​(int maxRetries)
        Parameters:
        maxRetries -
      • Retrier

        public Retrier​(int maxRetries,
                       int waitBetweenRetries,
                       int waitBetweenRetriesMultiplier)
        Parameters:
        maxRetries -
        waitBetweenRetries -
        waitBetweenRetriesMultiplier -
    • Method Detail

      • execute

        public <T> T execute​(Retriable retriable)
                      throws Exception
        Executes the action of a Retriable, and retries on error. Provides a way to execute a variety of methods and allow a retry to occur on method failure. Returns the necessary object type. This method, along with the Retriable interface is an implementation of the command pattern.
        Parameters:
        retriable -
        Throws:
        Exception
      • execute

        public <T> T execute​(Retriable retriable,
                             ExceptionHandler exceptionHandler)
                      throws Exception
        Executes the action of a Retriable, and retries on error. Provides a way to execute a variety of methods and allow a retry to occur on method failure. Returns the necessary object type.
        Parameters:
        retriable -
        exceptionHandler - for customing handling of exceptions - especially with respect to customized logging.
        Throws:
        Exception