Interface Retry
- All Superinterfaces:
FtHandler, RuntimeType.Api<RetryConfig>
Retry supports retry policies to be applied on an execution of asynchronous tasks.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA retry policy that prolongs the delays between retries by a defined factor.static classA retry policy that randomizes delays between execution using a "jitter" time.static interfaceRetry policy to handle delays between retries.static interfaceStrategy used to wait before another invocation attempt. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic RetryConfig.Builderbuilder()Create a new retry fluent API builder.static Retrycreate(RetryConfig retryConfig) Create a new retry from its configuration.static Retrycreate(Consumer<RetryConfig.Builder> builderConsumer) Create a new retry with customized configuration.default <T> Tinvoke(Function<RetryContext, ? extends T> function) Invoke a function with context for each attempt.default <T> Tinvoke(Function<RetryContext, ? extends T> function, Retry.WaitStrategy waitStrategy) Invoke a function with context for each attempt, using a caller-provided strategy to wait between attempts.longNumber of times a method called has been retried.Methods inherited from interface RuntimeType.Api
prototypeModifier and TypeMethodDescriptionThe prototype as it was received when creating this runtime object instance.
-
Field Details
-
FT_RETRY_CALLS_TOTAL
Counter for all the calls in a retry. Will always be greater thanFT_RETRY_RETRIES_TOTALthat only counts actual retries.- See Also:
-
FT_RETRY_RETRIES_TOTAL
Counter for all retry calls, excluding the initial call.- See Also:
-
-
Method Details
-
create
Create a new retry from its configuration.- Parameters:
retryConfig- configuration of the retry to create- Returns:
- a new retry
-
create
Create a new retry with customized configuration.- Parameters:
builderConsumer- consumer of builder- Returns:
- a new retry customized through builder
-
builder
-
retryCounter
long retryCounter()Number of times a method called has been retried. This is a monotonically increasing counter over the lifetime of the handler.- Returns:
- number of times a method is retried
-
invoke
Invoke a function with context for each attempt.Unlike
FtHandler.invoke(Supplier), an invocation that does not complete successfully always throws aRetryException. The exception contains the retry outcome, including a termination reason.- Type Parameters:
T- type of result- Parameters:
function- function invoked for each attempt- Returns:
- result obtained from the function
- Throws:
RetryException- if the invocation does not complete successfullyUnsupportedOperationException- if you use a custom retry implementation, and it does not implement this method
-
invoke
Invoke a function with context for each attempt, using a caller-provided strategy to wait between attempts.The wait strategy can perform work needed to keep a resource alive while waiting, or terminate retries by returning
false.- Type Parameters:
T- type of result- Parameters:
function- function invoked for each attemptwaitStrategy- strategy that waits between attempts- Returns:
- result obtained from the function
- Throws:
RetryException- if the invocation does not complete successfullyUnsupportedOperationException- if you use a custom retry implementation, and it does not implement this method
-