Class RetryingOperation<T>

java.lang.Object
com.northconcepts.datapipeline.retry.RetryingOperation<T>

public class RetryingOperation<T> extends Object
A proxy that attempts to re-run on failure.
  • Constructor Details

    • RetryingOperation

      public RetryingOperation()
  • Method Details

    • getMaxRetryCount

      public int getMaxRetryCount()
      Returns the number of retries allowed for any individual read attempt (default 5).
    • setMaxRetryCount

      public RetryingOperation<T> setMaxRetryCount(int maxRetryCount)
      Sets the number of retries allowed for any individual read attempt (default 5).
    • getMaxErrorCount

      public long getMaxErrorCount()
      Returns the number of retries allowed across all read attempts (default max long - 1).
    • setMaxErrorCount

      public RetryingOperation<T> setMaxErrorCount(long maxErrorCount)
      Sets the number of retries allowed across all read attempts (default max long -1).
    • getInitialRetryDelay

      public long getInitialRetryDelay()
      Returns the amount of time to wait (in milliseconds) after the first error, before retrying (default 1 second).
    • setInitialRetryDelay

      public RetryingOperation<T> setInitialRetryDelay(long initialRetryDelay)
      Sets the amount of time to wait (in milliseconds) after the first error, before retrying (default 1 second).
    • getStrategy

      public IRetryStrategy getStrategy()
      Returns the retry strategy (default RetryStrategy.EXPONENTIAL_BACKOFF).
    • setStrategy

      public RetryingOperation<T> setStrategy(IRetryStrategy strategy)
      Sets the retry strategy (default RetryStrategy.EXPONENTIAL_BACKOFF).
    • getExceptionCount

      public long getExceptionCount()
      Returns the total number of exceptions/failures seen by this reader. This value is also the number of retries as long as maxErrorCount hasn't been exceeded.
    • getFirstException

      public Throwable getFirstException()
      Returns the first exception thrown for any individual read attempt. This value will reset on the next read attempt after a successful retry.
    • getLastException

      public Throwable getLastException()
      Returns the last exception thrown for any individual read attempt. This value will reset on the next read attempt after a successful retry.
    • getRetryPredicate

      public Predicate<RetryContext> getRetryPredicate()
      Returns the predicate that determines whether to retry after a failure. The predicate is passed a RetryContext that contains information about the retry attempt. By default, the predicate always returns true, meaning that the operation will always retry until maxRetryCount or maxErrorCount is reached.
    • setRetryPredicate

      public RetryingOperation<T> setRetryPredicate(Predicate<RetryContext> predicate)
      Sets the predicate that determines whether to retry after a failure. The predicate is passed a RetryContext that contains information about the retry attempt. By default, the predicate always returns true, meaning that the operation will always retry until maxRetryCount or maxErrorCount is reached.
    • run

      public void run(Runnable runnable) throws Throwable
      Runs the runnable with the same retry behaviour as call(Callable).
      Throws:
      Throwable
    • call

      public T call(Callable<T> callable) throws Throwable
      Calls the callable, retrying failures with the strategy's delays for up to getMaxRetryCount() attempts in total; rethrows the last exception if none succeeds or the retry predicate declines.
      Throws:
      Throwable
    • onFailure

      protected void onFailure(Throwable exception) throws Throwable
      Called after each failed attempt; throws once the exception count exceeds getMaxErrorCount().
      Throws:
      Throwable