Class KiwiRetryer<T>


  • public class KiwiRetryer<T>
    extends Object
    This is a wrapper class for Retryer; it wraps methods so that the RetryException and InterruptedException that are generated from the Retryer.call(Callable) method are converted to KiwiRetryerException. The Background Information section at the bottom gives some history on why this is even here in the first place. You might consider using Retryer directly now that it is within org.kiwiproject as the standalone retrying-again library.

    It also provides some kiwi-flavored default values, an identifier that can be used to distinguish between retryer instances in logs, logging of retry attempts, and some factories for creating retryer instances with common behavior.

    You can construct a KiwiRetryer using the builder obtained via KiwiRetryer.builder().

    Available configuration options for KiwiRetryer:
    Name Default Description
    retryerId UUID generated by UUIDs.randomUUIDString() The identifier for the retryer
    initialSleepTimeAmount 100 The initial sleep amount for the default incrementing wait strategy. This value will be ignored if an explicit WaitStrategy is defined.
    initialSleepTimeUnit TimeUnit.MILLISECONDS The initial sleep TimeUnit for the default incrementing wait strategy. This value will be ignored if an explicit WaitStrategy is defined.
    retryIncrementTimeAmount 200 The subsequent retry increment amount for the default incrementing wait strategy. This value will be ignored if an explicit WaitStrategy is defined.
    retryIncrementTimeUnit TimeUnit.MILLISECONDS The subsequent retry increment TimeUnit for the default incrementing wait strategy. This value will be ignored if an explicit WaitStrategy is defined.
    maxAttempts 5 The maximum number of attempts to use for the default stop strategy. This value will be ignored if an explicit StopStrategy is defined.
    processingLogLevel Level.DEBUG This log level controls the "happy path" messages that are logged by this retryer.
    exceptionLogLevel Level.WARN This log level controls the "sad path" messages (i.e. exceptions) that are logged by this retryer.
    retryOnAllExceptions false Tells the retryer to retry on any exception. NOTE: This supersedes any exceptions added to the exceptionPredicates list or if retryOnAllRuntimeExceptions is set to true
    retryOnAllRuntimeExceptions false Tells the retryer to retry on all RuntimeExceptions. NOTE: This supersedes any exceptions added to the exceptionPredicates list.
    exceptionPredicates empty list Defines the Exceptions that should cause KiwiRetryer to retry its specified Callable if encountered during processing.
    resultPredicates empty list Defines the T objects that should cause KiwiRetryer to retry its specified Callable if returned by the Callable during processing.
    stopStrategy null An explicit stopStrategy which will override the default stop after attempts stop strategy.
    waitStrategy null An explicit waitStrategy which will override the default incrementing wait strategy.

    Background Information:

    Originally this class was created to wrap the (now defunct) guava-retrying library and add various defaults and conveniences, as well as an easier way to handle RetryException and its causes. The guava-retrying library stopped being maintained circa 2016, and was forked into re-retrying, which then stopped active development circa 2018. So, in late 2020 we forked re-retrying as retrying-again in order to keep it up to date at a minimum, and hopefully add some additional value where it makes sense. It is possible we might simply move some of this functionality into retrying-again and then deprecate and remove this functionality from kiwi. That would also allow us to use kiwi from retrying-again, which we currently cannot do without introducing a circular dependency.

    NOTE: The org.kiwiproject:retrying-again library must be available at runtime.