- java.lang.Object
-
- com.github.mizosoft.methanol.RetryInterceptor.Builder
-
- Enclosing class:
- RetryInterceptor
public static final class RetryInterceptor.Builder extends java.lang.ObjectA builder ofRetryInterceptorinstances.Note: Retry conditions are evaluated in the order they are added. The first matching condition determines the next request. Later conditions are not evaluated.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RetryInterceptor.Builderbackoff(RetryInterceptor.BackoffStrategy backoffStrategy)Specifies theBackoffStrategyto apply every retry.RetryInterceptor.BuilderbeginWith(java.util.function.Function<java.net.http.HttpRequest,java.net.http.HttpRequest> requestModifier)Specifies the request modifier to be applied before the request is sent for the first time (attempt 0, not a retry).RetryInterceptorbuild()Builds a newRetryInterceptorthat retries all requests based on the conditions specified so far.RetryInterceptorbuild(java.util.function.BiPredicate<java.net.http.HttpRequest,Methanol.Interceptor.Chain<?>> selector)Builds a newRetryInterceptorthat only retries requests matched by the given predicate based on the conditions specified so far.RetryInterceptorbuild(java.util.function.Predicate<java.net.http.HttpRequest> selector)Builds a newRetryInterceptorthat only retries requests matched by the given predicate based on the conditions specified so far.RetryInterceptor.Builderlistener(RetryInterceptor.Listener listener)Sets the listener for retry events.RetryInterceptor.BuildermaxRetries(int maxRetries)Specifies the maximum times the interceptor is allowed to retry the request.RetryInterceptor.Builderon(java.util.function.Predicate<RetryInterceptor.Context<?>> predicate)Specifies that the interceptor is to retry the request if the retryRetryInterceptor.Contextsatisfies the given predicate.RetryInterceptor.Builderon(java.util.function.Predicate<RetryInterceptor.Context<?>> predicate, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)Specifies that the interceptor is to retry the request, after applying the given request modifier, if the retryRetryInterceptor.Contextsatisfies the given predicate.RetryInterceptor.BuilderonException(java.lang.Class<? extends java.lang.Throwable>... exceptionTypes)Specifies that the interceptor is to retry the request if an exception with any of the given types is thrown.RetryInterceptor.BuilderonException(java.util.function.Predicate<java.lang.Throwable> exceptionPredicate)Specifies that the interceptor is to retry the request if an exception that satisfies the given predicate is thrown.RetryInterceptor.BuilderonException(java.util.function.Predicate<java.lang.Throwable> exceptionPredicate, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)Specifies that the interceptor is to retry the request, after applying the given request modifier, if an exception that satisfies the given predicate is thrown.RetryInterceptor.BuilderonException(java.util.Set<java.lang.Class<? extends java.lang.Throwable>> exceptionTypes, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)Specifies that the interceptor is to retry the request, after applying the given request modifier, if an exception with any of the given types is thrown.RetryInterceptor.BuilderonResponse(java.util.function.Predicate<java.net.http.HttpResponse<?>> responsePredicate)Specifies that the interceptor is to retry the request if a response that satisfies the given predicate is received.RetryInterceptor.BuilderonResponse(java.util.function.Predicate<java.net.http.HttpResponse<?>> responsePredicate, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)Specifies that the interceptor is to retry the request, after applying the given request modifier, if a response that satisfies the given predicate is received.RetryInterceptor.BuilderonStatus(int... codes)Specifies that the interceptor is to retry the request if a response with any of the given status codes is received.RetryInterceptor.BuilderonStatus(java.util.function.Predicate<java.lang.Integer> statusPredicate)Specifies that the interceptor is to retry the request if a response whose code satisfies the given predicate is received.RetryInterceptor.BuilderonStatus(java.util.function.Predicate<java.lang.Integer> statusPredicate, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)Specifies that the interceptor is to retry the request, after applying the given request modifier, if a response whose code satisfies the given predicate is received.RetryInterceptor.BuilderonStatus(java.util.Set<java.lang.Integer> codes, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)Specifies that the interceptor is to retry the request, after applying the given request modifier, if a response with any of the given status codes is received.RetryInterceptor.BuilderretryNonIdempotent()Specifies that requests that are not idempotent are to be retried.RetryInterceptor.BuilderthrowOnExhaustion()Specifies that the interceptor is to throw anHttpRetriesExhaustedExceptionif the maximum number of retries is exceeded, with the last-thrown exception (if any) added as a suppressed exception.RetryInterceptor.Buildertimeout(java.time.Duration timeout)Sets a timeout for the entire retry process.
-
-
-
Method Detail
-
beginWith
@CanIgnoreReturnValue public RetryInterceptor.Builder beginWith(java.util.function.Function<java.net.http.HttpRequest,java.net.http.HttpRequest> requestModifier)
Specifies the request modifier to be applied before the request is sent for the first time (attempt 0, not a retry). This can be used to add request headers that should be present on all attempts.
-
maxRetries
@CanIgnoreReturnValue public RetryInterceptor.Builder maxRetries(int maxRetries)
Specifies the maximum times the interceptor is allowed to retry the request. After the given number of retries is exhausted, the interceptor returns the request or exception as-is, or throws anHttpRetriesExhaustedExceptionifthrowOnExhaustion()is specified. The defaultmaxRetriesis 5.
-
backoff
@CanIgnoreReturnValue public RetryInterceptor.Builder backoff(RetryInterceptor.BackoffStrategy backoffStrategy)
Specifies theBackoffStrategyto apply every retry. The defaultBackoffStrategyisRetryInterceptor.BackoffStrategy.none().
-
onException
@SafeVarargs @CanIgnoreReturnValue public final RetryInterceptor.Builder onException(java.lang.Class<? extends java.lang.Throwable>... exceptionTypes)
Specifies that the interceptor is to retry the request if an exception with any of the given types is thrown.
-
onException
@CanIgnoreReturnValue public RetryInterceptor.Builder onException(java.util.Set<java.lang.Class<? extends java.lang.Throwable>> exceptionTypes, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)
Specifies that the interceptor is to retry the request, after applying the given request modifier, if an exception with any of the given types is thrown.
-
onException
@CanIgnoreReturnValue public RetryInterceptor.Builder onException(java.util.function.Predicate<java.lang.Throwable> exceptionPredicate)
Specifies that the interceptor is to retry the request if an exception that satisfies the given predicate is thrown.
-
onException
@CanIgnoreReturnValue public RetryInterceptor.Builder onException(java.util.function.Predicate<java.lang.Throwable> exceptionPredicate, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)
Specifies that the interceptor is to retry the request, after applying the given request modifier, if an exception that satisfies the given predicate is thrown.
-
onStatus
@CanIgnoreReturnValue public RetryInterceptor.Builder onStatus(int... codes)
Specifies that the interceptor is to retry the request if a response with any of the given status codes is received.
-
onStatus
@CanIgnoreReturnValue public RetryInterceptor.Builder onStatus(java.util.Set<java.lang.Integer> codes, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)
Specifies that the interceptor is to retry the request, after applying the given request modifier, if a response with any of the given status codes is received.
-
onStatus
@CanIgnoreReturnValue public RetryInterceptor.Builder onStatus(java.util.function.Predicate<java.lang.Integer> statusPredicate)
Specifies that the interceptor is to retry the request if a response whose code satisfies the given predicate is received.
-
onStatus
@CanIgnoreReturnValue public RetryInterceptor.Builder onStatus(java.util.function.Predicate<java.lang.Integer> statusPredicate, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)
Specifies that the interceptor is to retry the request, after applying the given request modifier, if a response whose code satisfies the given predicate is received.
-
onResponse
@CanIgnoreReturnValue public RetryInterceptor.Builder onResponse(java.util.function.Predicate<java.net.http.HttpResponse<?>> responsePredicate)
Specifies that the interceptor is to retry the request if a response that satisfies the given predicate is received.
-
onResponse
@CanIgnoreReturnValue public RetryInterceptor.Builder onResponse(java.util.function.Predicate<java.net.http.HttpResponse<?>> responsePredicate, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)
Specifies that the interceptor is to retry the request, after applying the given request modifier, if a response that satisfies the given predicate is received.
-
on
@CanIgnoreReturnValue public RetryInterceptor.Builder on(java.util.function.Predicate<RetryInterceptor.Context<?>> predicate)
Specifies that the interceptor is to retry the request if the retryRetryInterceptor.Contextsatisfies the given predicate.
-
on
@CanIgnoreReturnValue public RetryInterceptor.Builder on(java.util.function.Predicate<RetryInterceptor.Context<?>> predicate, java.util.function.Function<RetryInterceptor.Context<?>,java.net.http.HttpRequest> requestModifier)
Specifies that the interceptor is to retry the request, after applying the given request modifier, if the retryRetryInterceptor.Contextsatisfies the given predicate.
-
timeout
@CanIgnoreReturnValue public RetryInterceptor.Builder timeout(java.time.Duration timeout)
Sets a timeout for the entire retry process. If the timeout is exceeded before receiving a non-retryable response or exception, anHttpTimeoutExceptionis thrown with the last exception (if any) as a suppressed exception.The timeout applies from the start of the first attempt until either:
- A non-retryable response or exception is received
- Maximum retries are exhausted
- The timeout expires
-
listener
@CanIgnoreReturnValue public RetryInterceptor.Builder listener(RetryInterceptor.Listener listener)
Sets the listener for retry events.
-
throwOnExhaustion
@CanIgnoreReturnValue public RetryInterceptor.Builder throwOnExhaustion()
Specifies that the interceptor is to throw anHttpRetriesExhaustedExceptionif the maximum number of retries is exceeded, with the last-thrown exception (if any) added as a suppressed exception.By default, when retries are exhausted, the last response or exception is returned/thrown as-is. This allows you to specify a "give up and throw" behavior on the interceptor.
-
retryNonIdempotent
@CanIgnoreReturnValue public RetryInterceptor.Builder retryNonIdempotent()
Specifies that requests that are not idempotent are to be retried. By default, only idempotent requests are retried.
-
build
public RetryInterceptor build()
Builds a newRetryInterceptorthat retries all requests based on the conditions specified so far.
-
build
public RetryInterceptor build(java.util.function.Predicate<java.net.http.HttpRequest> selector)
Builds a newRetryInterceptorthat only retries requests matched by the given predicate based on the conditions specified so far.
-
build
public RetryInterceptor build(java.util.function.BiPredicate<java.net.http.HttpRequest,Methanol.Interceptor.Chain<?>> selector)
Builds a newRetryInterceptorthat only retries requests matched by the given predicate based on the conditions specified so far.
-
-