java.lang.Object
com.linecorp.armeria.common.util.AbstractUnwrappable<Client<T_I,T_O>>
com.linecorp.armeria.client.DecoratingClient<I,O,I,O>
com.linecorp.armeria.client.SimpleDecoratingClient<I,O>
com.linecorp.armeria.client.retry.AbstractRetryingClient<I,O>
- All Implemented Interfaces:
Client<I,
,O> Unwrappable
- Direct Known Subclasses:
RetryingClient
,RetryingRpcClient
public abstract class AbstractRetryingClient<I extends Request,O extends Response>
extends SimpleDecoratingClient<I,O>
A
Client
decorator that handles failures of remote invocation and retries requests.-
Field Summary
Modifier and TypeFieldDescriptionstatic final AsciiString
The header which indicates the retry count of aRequest
. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract O
doExecute
(ClientRequestContext ctx, I req) Invoked byexecute(ClientRequestContext, Request)
after the deadline for response timeout is set.final O
execute
(ClientRequestContext ctx, I req) protected final long
getNextDelay
(ClientRequestContext ctx, Backoff backoff) Returns the next delay which retry will be made after.protected final long
getNextDelay
(ClientRequestContext ctx, Backoff backoff, long millisAfterFromServer) Returns the next delay which retry will be made after.protected static int
Returns the total number of attempts of the current request represented by the specifiedClientRequestContext
.protected final RetryConfigMapping<O>
mapping()
Returns the currentRetryConfigMapping
set for this client.protected static ClientRequestContext
newDerivedContext
(ClientRequestContext ctx, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq, boolean initialAttempt) Creates a new derivedClientRequestContext
, replacing the requests.protected static void
This should be called when retrying is finished.protected final RetryRule
Returns theRetryRule
.protected final RetryRuleWithContent<O>
Returns theRetryRuleWithContent
.protected static void
scheduleNextRetry
(ClientRequestContext ctx, Consumer<? super Throwable> actionOnException, Runnable retryTask, long nextDelayMillis) Schedules next retry.protected final boolean
Resets theClientRequestContext.responseTimeoutMillis()
.Methods inherited from class com.linecorp.armeria.common.util.AbstractUnwrappable
as, toString, unwrap, unwrapAll
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.common.util.Unwrappable
equalsIgnoreWrapper, unwrapAll
-
Field Details
-
ARMERIA_RETRY_COUNT
The header which indicates the retry count of aRequest
. The server might use this value to reject excessive retries, etc.
-
-
Method Details
-
execute
Description copied from interface:Client
-
mapping
Returns the currentRetryConfigMapping
set for this client. -
doExecute
Invoked byexecute(ClientRequestContext, Request)
after the deadline for response timeout is set.- Throws:
Exception
-
onRetryingComplete
This should be called when retrying is finished. -
retryRule
Returns theRetryRule
.- Throws:
IllegalStateException
- if theRetryRule
is not set
-
retryRuleWithContent
Returns theRetryRuleWithContent
.- Throws:
IllegalStateException
- if theRetryRuleWithContent
is not set
-
scheduleNextRetry
protected static void scheduleNextRetry(ClientRequestContext ctx, Consumer<? super Throwable> actionOnException, Runnable retryTask, long nextDelayMillis) Schedules next retry. -
setResponseTimeout
Resets theClientRequestContext.responseTimeoutMillis()
.- Returns:
true
if the response timeout is set,false
if it can't be set due to the timeout
-
getNextDelay
Returns the next delay which retry will be made after. The delay will be:Math.min(responseTimeoutMillis, Backoff.nextDelayMillis(int))
- Returns:
- the number of milliseconds to wait for before attempting a retry. -1 if the
currentAttemptNo
exceeds themaxAttempts
or thenextDelay
is after the moment which timeout happens.
-
getNextDelay
protected final long getNextDelay(ClientRequestContext ctx, Backoff backoff, long millisAfterFromServer) Returns the next delay which retry will be made after. The delay will be:Math.min(responseTimeoutMillis, Math.max(Backoff.nextDelayMillis(int), millisAfterFromServer))
- Returns:
- the number of milliseconds to wait for before attempting a retry. -1 if the
currentAttemptNo
exceeds themaxAttempts
or thenextDelay
is after the moment which timeout happens.
-
getTotalAttempts
Returns the total number of attempts of the current request represented by the specifiedClientRequestContext
. -
newDerivedContext
protected static ClientRequestContext newDerivedContext(ClientRequestContext ctx, @Nullable @Nullable HttpRequest req, @Nullable @Nullable RpcRequest rpcReq, boolean initialAttempt) Creates a new derivedClientRequestContext
, replacing the requests. IfClientRequestContext.endpointGroup()
exists, a newEndpoint
will be selected.
-