@FunctionalInterface public interface RetryStrategy
Response, use RetryStrategyWithContent.| Modifier and Type | Field and Description |
|---|---|
static Backoff |
defaultBackoff
Deprecated.
Use
Backoff.ofDefault(). |
| Modifier and Type | Method and Description |
|---|---|
static RetryStrategy |
never()
A
RetryStrategy that defines a retry should not be performed. |
static RetryStrategy |
onServerErrorStatus()
Returns the
RetryStrategy that retries the request with the Backoff.ofDefault()
when the response status matches HttpStatusClass.SERVER_ERROR or an Exception is raised. |
static RetryStrategy |
onServerErrorStatus(Backoff backoff)
Returns the
RetryStrategy that retries the request with the specified backoff
when the response status matches HttpStatusClass.SERVER_ERROR or an Exception is raised. |
static RetryStrategy |
onStatus(BiFunction<HttpStatus,Throwable,Backoff> backoffFunction)
Returns the
RetryStrategy that decides to retry the request using the specified
backoffFunction. |
static RetryStrategy |
onUnprocessed()
|
static RetryStrategy |
onUnprocessed(Backoff backoff)
|
CompletionStage<Backoff> |
shouldRetry(ClientRequestContext ctx,
Throwable cause)
Tells whether the request sent with the specified
ClientRequestContext requires a retry or not. |
@Deprecated static final Backoff defaultBackoff
Backoff.ofDefault().Backoff implementation.static RetryStrategy never()
RetryStrategy that defines a retry should not be performed.static RetryStrategy onUnprocessed()
static RetryStrategy onUnprocessed(Backoff backoff)
static RetryStrategy onServerErrorStatus()
RetryStrategy that retries the request with the Backoff.ofDefault()
when the response status matches HttpStatusClass.SERVER_ERROR or an Exception is raised.static RetryStrategy onServerErrorStatus(Backoff backoff)
RetryStrategy that retries the request with the specified backoff
when the response status matches HttpStatusClass.SERVER_ERROR or an Exception is raised.static RetryStrategy onStatus(BiFunction<HttpStatus,Throwable,Backoff> backoffFunction)
RetryStrategy that decides to retry the request using the specified
backoffFunction.backoffFunction - the BiFunction that returns the Backoff or null
according to the HttpStatus and ThrowableCompletionStage<Backoff> shouldRetry(ClientRequestContext ctx, Throwable cause)
ClientRequestContext requires a retry or not.
Implement this method to return a CompletionStage and to complete it with a desired
Backoff. To stop trying further, complete it with null.
To retrieve the ResponseHeaders, you can use the specified ClientRequestContext:
CompletionStage<Backoff> shouldRetry(ClientRequestContext ctx, @Nullable Throwable cause) {
if (cause != null) {
return CompletableFuture.completedFuture(backoff);
}
ResponseHeaders responseHeaders = ctx.log().responseHeaders();
if (responseHeaders.status().codeClass() == HttpStatusClass.SERVER_ERROR) {
return CompletableFuture.completedFuture(backoff);
}
...
}
ctx - the ClientRequestContext of this requestcause - the Throwable which is raised while sending a request. null it there's no
exception.Copyright © 2020 LeanCloud. All rights reserved.