public abstract class AbstractRetryingClient<I extends Request,O extends Response> extends SimpleDecoratingClient<I,O>
Client decorator that handles failures of remote invocation and retries requests.| Modifier and Type | Field and Description |
|---|---|
static io.netty.util.AsciiString |
ARMERIA_RETRY_COUNT
The header which indicates the retry count of a
Request. |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractRetryingClient(Client<I,O> delegate,
RetryStrategy retryStrategy,
int maxTotalAttempts,
long responseTimeoutMillisForEachAttempt)
Creates a new instance that decorates the specified
Client. |
protected |
AbstractRetryingClient(Client<I,O> delegate,
RetryStrategyWithContent<O> retryStrategyWithContent,
int maxTotalAttempts,
long responseTimeoutMillisForEachAttempt)
Creates a new instance that decorates the specified
Client. |
| Modifier and Type | Method and Description |
|---|---|
protected abstract O |
doExecute(ClientRequestContext ctx,
I req)
Invoked by
execute(ClientRequestContext, Request)
after the deadline for response timeout is set. |
O |
execute(ClientRequestContext ctx,
I req)
|
protected long |
getNextDelay(ClientRequestContext ctx,
Backoff backoff)
Returns the next delay which retry will be made after.
|
protected long |
getNextDelay(ClientRequestContext ctx,
Backoff backoff,
long millisAfterFromServer)
Returns the next delay which retry will be made after.
|
protected static int |
getTotalAttempts(ClientRequestContext ctx)
Returns the total number of attempts of the current request represented by the specified
ClientRequestContext. |
protected static ClientRequestContext |
newDerivedContext(ClientRequestContext ctx,
HttpRequest req,
RpcRequest rpcReq,
boolean initialAttempt)
Creates a new derived
ClientRequestContext, replacing the requests. |
protected static void |
onRetryingComplete(ClientRequestContext ctx)
This should be called when retrying is finished.
|
protected RetryStrategy |
retryStrategy()
Returns the
RetryStrategy. |
protected RetryStrategyWithContent<O> |
retryStrategyWithContent()
Returns the
RetryStrategyWithContent. |
protected static void |
scheduleNextRetry(ClientRequestContext ctx,
Consumer<? super Throwable> actionOnException,
Runnable retryTask,
long nextDelayMillis)
Schedules next retry.
|
protected boolean |
setResponseTimeout(ClientRequestContext ctx)
Resets the
ClientRequestContext.responseTimeoutMillis(). |
as, delegate, toStringpublic static final io.netty.util.AsciiString ARMERIA_RETRY_COUNT
Request.
The server might use this value to reject excessive retries, etc.protected AbstractRetryingClient(Client<I,O> delegate, RetryStrategy retryStrategy, int maxTotalAttempts, long responseTimeoutMillisForEachAttempt)
Client.public O execute(ClientRequestContext ctx, I req) throws Exception
Clientprotected abstract O doExecute(ClientRequestContext ctx, I req) throws Exception
execute(ClientRequestContext, Request)
after the deadline for response timeout is set.Exceptionprotected static void onRetryingComplete(ClientRequestContext ctx)
protected RetryStrategy retryStrategy()
RetryStrategy.IllegalStateException - if the RetryStrategy is not setprotected RetryStrategyWithContent<O> retryStrategyWithContent()
RetryStrategyWithContent.IllegalStateException - if the RetryStrategyWithContent is not setprotected static void scheduleNextRetry(ClientRequestContext ctx, Consumer<? super Throwable> actionOnException, Runnable retryTask, long nextDelayMillis)
protected final boolean setResponseTimeout(ClientRequestContext ctx)
ClientRequestContext.responseTimeoutMillis().true if the response timeout is set, false if it can't be set due to the timeoutprotected final long getNextDelay(ClientRequestContext ctx, Backoff backoff)
Math.min(responseTimeoutMillis, Backoff.nextDelayMillis(int))
currentAttemptNo exceeds the maxAttempts or the nextDelay is after
the moment which timeout happens.protected final long getNextDelay(ClientRequestContext ctx, Backoff backoff, long millisAfterFromServer)
Math.min(responseTimeoutMillis, Math.max(Backoff.nextDelayMillis(int),
millisAfterFromServer))
currentAttemptNo exceeds the maxAttempts or the nextDelay is after
the moment which timeout happens.protected static int getTotalAttempts(ClientRequestContext ctx)
ClientRequestContext.protected static ClientRequestContext newDerivedContext(ClientRequestContext ctx, HttpRequest req, RpcRequest rpcReq, boolean initialAttempt)
ClientRequestContext, replacing the requests.
If ClientRequestContext.endpointGroup() exists, a new Endpoint will be selected.Copyright © 2020 LeanCloud. All rights reserved.