Class KiwiRetryer<T>
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().
| 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.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> KiwiRetryer.KiwiRetryerBuilder<T>builder()Invoke the retryer with the given ID andCallable.Invoke the retryer with the givenCallable.static <T> KiwiRetryer<T>newRetryerRetryingAllExceptions(String retryerId) Create a new instance that will retry on all exceptions.static <T> KiwiRetryer<T>newRetryerRetryingAllRuntimeExceptions(String retryerId) Create a new instance that will retry on all runtime exceptions.static <T> KiwiRetryer<T>newRetryerWithDefaultExceptions(String retryerId) Create a new instance with several common network-related exception predicates.static <T> KiwiRetryer<T>Create a new instance with only the default values.
-
Method Details
-
newRetryerWithDefaults
Create a new instance with only the default values.- Type Parameters:
T- type of object the retryer returns- Returns:
- a KiwiRetryer for type
T
-
newRetryerWithDefaultExceptions
Create a new instance with several common network-related exception predicates.- Type Parameters:
T- type of object the retryer returns- Parameters:
retryerId- the retryer ID- Returns:
- a KiwiRetryer for type
T - See Also:
-
newRetryerRetryingAllExceptions
Create a new instance that will retry on all exceptions.- Type Parameters:
T- type of object the retryer returns- Parameters:
retryerId- the retryer ID- Returns:
- a KiwiRetryer for type
T
-
newRetryerRetryingAllRuntimeExceptions
Create a new instance that will retry on all runtime exceptions.- Type Parameters:
T- type of object the retryer returns- Parameters:
retryerId- the retryer ID- Returns:
- a KiwiRetryer for type
T
-
call
Invoke the retryer with the givenCallable.- Parameters:
callable- the code that attempts to produce a result- Returns:
- the result of the
Callable - Throws:
KiwiRetryerException- if there was an unhandled exception during processing, or if the maximum number of attempts was reached without success. For further information about the cause, you can unwrap the exception.- See Also:
-
call
Invoke the retryer with the given ID andCallable.This method allows you to use different IDs with the same
KiwiRetryerinstance, for example if the same retryer is called in separate threads it will be useful to be able to distinguish between them in logs.- Parameters:
retryerId- the ID for this retryer call (overrides theretryerIdof this instance)callable- the code that attempts to produce a result- Returns:
- the result of the
Callable - Throws:
KiwiRetryerException- if there was an unhandled exception during processing, or if the maximum number of attempts was reached without success. For further information about the cause, you can unwrap the exception.- See Also:
-
builder
-