Class RetryingCallbackHelper


  • public class RetryingCallbackHelper
    extends Object
    A helper that runs a unit of work, transparently retrying the unit of work if an error occurs.

    Defaults:

    • maxRetries: 5
    • retryWaitMs: 10
    Since:
    3.4
    Author:
    Derek Hulley
    • Constructor Detail

      • RetryingCallbackHelper

        public RetryingCallbackHelper()
        Default constructor.
    • Method Detail

      • setMaxRetries

        public void setMaxRetries​(int maxRetries)
        Set the maximimum number of retries. -1 for infinity.
      • setRetryWaitMs

        public void setRetryWaitMs​(int retryWaitMs)
      • doWithRetry

        public <R> R doWithRetry​(RetryingCallbackHelper.RetryingCallback<R> callback)
        Execute a callback until it succeeds, fails or until a maximum number of retries have been attempted.
        Parameters:
        callback - The callback containing the unit of work.
        Returns:
        Returns the result of the unit of work.
        Throws:
        RuntimeException - all checked exceptions are converted