- java.lang.Object
-
- com.github.mizosoft.methanol.RetryInterceptor
-
- All Implemented Interfaces:
Methanol.Interceptor
public final class RetryInterceptor extends java.lang.Object implements Methanol.Interceptor
An interceptor that retries HTTP requests based on configurable conditions.Retry conditions are evaluated in the order they are added. The first matching condition determines the next request to send. Later conditions are not evaluated.
Example:
Retry server errors with exponential backoff:var client = Methanol.newBuilder() .interceptor(RetryInterceptor.newBuilder() .maxRetries(3) .backoff(BackoffStrategy.exponential( Duration.ofMillis(100), Duration.ofSeconds(10)).withJitter()) .onStatus(500, 502, 503, 504) .onException(ConnectException.class) .build()) .build();- See Also:
RetryInterceptor.Builder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRetryInterceptor.BackoffStrategyA strategy for backing off (delaying) before a retry.static classRetryInterceptor.BuilderA builder ofRetryInterceptorinstances.static interfaceRetryInterceptor.Context<T>Context for deciding whether an HTTP call should be retried.static interfaceRetryInterceptor.ListenerA listener forRetryInterceptorevents.-
Nested classes/interfaces inherited from interface com.github.mizosoft.methanol.Methanol.Interceptor
Methanol.Interceptor.Chain<T>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> java.net.http.HttpResponse<T>intercept(java.net.http.HttpRequest request, Methanol.Interceptor.Chain<T> chain)Intercepts given request and returns the resulting response, usually by forwarding to the given chain.<T> java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>>interceptAsync(java.net.http.HttpRequest request, Methanol.Interceptor.Chain<T> chain)Intercepts the given request and returns aCompletableFuturefor the resulting response, usually by forwarding to the given chain.static RetryInterceptor.BuildernewBuilder()Returns a new builder ofRetryInterceptorinstances.
-
-
-
Method Detail
-
intercept
public <T> java.net.http.HttpResponse<T> intercept(java.net.http.HttpRequest request, Methanol.Interceptor.Chain<T> chain) throws java.io.IOException, java.lang.InterruptedExceptionDescription copied from interface:Methanol.InterceptorIntercepts given request and returns the resulting response, usually by forwarding to the given chain.- Specified by:
interceptin interfaceMethanol.Interceptor- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
interceptAsync
public <T> java.util.concurrent.CompletableFuture<java.net.http.HttpResponse<T>> interceptAsync(java.net.http.HttpRequest request, Methanol.Interceptor.Chain<T> chain)Description copied from interface:Methanol.InterceptorIntercepts the given request and returns aCompletableFuturefor the resulting response, usually by forwarding to the given chain.- Specified by:
interceptAsyncin interfaceMethanol.Interceptor
-
newBuilder
public static RetryInterceptor.Builder newBuilder()
Returns a new builder ofRetryInterceptorinstances.
-
-