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
Fields Modifier and Type Field Description static AsciiString
ARMERIA_RETRY_COUNT
The header which indicates the retry count of aRequest
. -
Method Summary
Modifier and Type Method Description protected abstract O
doExecute(ClientRequestContext ctx, I req)
Invoked byexecute(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 specifiedClientRequestContext
.protected RetryConfigMapping<O>
mapping()
Returns the currentRetryConfigMapping
set for this client.protected static ClientRequestContext
newDerivedContext(ClientRequestContext ctx, HttpRequest req, RpcRequest rpcReq, boolean initialAttempt)
Creates a new derivedClientRequestContext
, replacing the requests.protected static void
onRetryingComplete(ClientRequestContext ctx)
This should be called when retrying is finished.protected RetryRule
retryRule()
Returns theRetryRule
.protected RetryRuleWithContent<O>
retryRuleWithContent()
Returns theRetryRuleWithContent
.protected static void
scheduleNextRetry(ClientRequestContext ctx, Consumer<? super Throwable> actionOnException, Runnable retryTask, long nextDelayMillis)
Schedules next retry.protected boolean
setResponseTimeout(ClientRequestContext ctx)
Resets theClientRequestContext.responseTimeoutMillis()
.Methods inherited from class com.linecorp.armeria.common.util.AbstractUnwrappable
as, toString, unwrap
-
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 HttpRequest req, @Nullable RpcRequest rpcReq, boolean initialAttempt)Creates a new derivedClientRequestContext
, replacing the requests. IfClientRequestContext.endpointGroup()
exists, a newEndpoint
will be selected.
-