Class RetryManager

java.lang.Object
com.peterphi.std.guice.common.retry.retry.RetryManager

public class RetryManager extends Object
  • Constructor Details

    • RetryManager

      public RetryManager(BackoffStrategy strategy, int maxAttempts, com.codahale.metrics.Timer attempts, com.codahale.metrics.Meter attemptFailures)
  • Method Details

    • run

      public <T> T run(Retryable<T> operation) throws Exception
      Throws:
      Exception
    • maxAttemptsReached

      protected boolean maxAttemptsReached(int attempt)
      Returns true if the given attempt number is greater than or equal to the maximum number of attempts this retry manager should run
      Parameters:
      attempt -
      Returns:
    • finalAttemptFailed

      protected <T> T finalAttemptFailed(Retryable<T> operation, int attempt, boolean logError, Throwable e) throws Exception
      Called when the final attempt at a retryable operation failed

      Allows extending classes to customise behaviour or throw custom exceptions

      Parameters:
      operation - - the operation being attempted
      attempt - - the attempt number that failed
      logError - if true, log the failure
      e - - the exception thrown when the operation failed
      Throws:
      Exception
    • runUnchecked

      public <T> T runUnchecked(Retryable<T> operation) throws RuntimeException
      Run the operation, only throwing an unchecked exception on failure
      Type Parameters:
      T -
      Parameters:
      operation -
      Returns:
      Throws:
      RuntimeException