- java.lang.Object
-
- com.linecorp.armeria.client.DecoratingClient<I,O,I,O>
-
- com.linecorp.armeria.client.SimpleDecoratingClient<I,O>
-
- com.linecorp.armeria.client.retry.RetryingClient<I,O>
-
- All Implemented Interfaces:
Client<I,O>
- Direct Known Subclasses:
RetryingHttpClient
,RetryingRpcClient
public abstract class RetryingClient<I extends Request,O extends Response> extends SimpleDecoratingClient<I,O>
AClient
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
.
-
Constructor Summary
Constructors Modifier Constructor Description protected
RetryingClient(Client<I,O> delegate, RetryStrategy retryStrategy, int maxTotalAttempts, long responseTimeoutMillisForEachAttempt)
Creates a new instance that decorates the specifiedClient
.protected
RetryingClient(Client<I,O> delegate, RetryStrategyWithContent<O> retryStrategyWithContent, int maxTotalAttempts, long responseTimeoutMillisForEachAttempt)
Creates a new instance that decorates the specifiedClient
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 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 static void
onRetryingComplete(ClientRequestContext ctx)
This should be called when retrying is finished.protected RetryStrategy
retryStrategy()
Returns theRetryStrategy
.protected RetryStrategyWithContent<O>
retryStrategyWithContent()
Returns theRetryStrategyWithContent
.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.client.DecoratingClient
delegate, toString
-
-
-
-
Field Detail
-
ARMERIA_RETRY_COUNT
public static final AsciiString ARMERIA_RETRY_COUNT
The header which indicates the retry count of aRequest
. The server might use this value to reject excessive retries, etc.
-
-
Constructor Detail
-
RetryingClient
protected RetryingClient(Client<I,O> delegate, RetryStrategy retryStrategy, int maxTotalAttempts, long responseTimeoutMillisForEachAttempt)
Creates a new instance that decorates the specifiedClient
.
-
-
Method Detail
-
execute
public O execute(ClientRequestContext ctx, I req) throws Exception
Description copied from interface:Client
-
doExecute
protected abstract O doExecute(ClientRequestContext ctx, I req) throws Exception
Invoked byexecute(ClientRequestContext, Request)
after the deadline for response timeout is set.- Throws:
Exception
-
onRetryingComplete
protected static void onRetryingComplete(ClientRequestContext ctx)
This should be called when retrying is finished.
-
retryStrategy
protected RetryStrategy retryStrategy()
Returns theRetryStrategy
.- Throws:
IllegalStateException
- if theRetryStrategy
is not set
-
retryStrategyWithContent
protected RetryStrategyWithContent<O> retryStrategyWithContent()
Returns theRetryStrategyWithContent
.- Throws:
IllegalStateException
- if theRetryStrategyWithContent
is not set
-
scheduleNextRetry
protected static void scheduleNextRetry(ClientRequestContext ctx, Consumer<? super Throwable> actionOnException, Runnable retryTask, long nextDelayMillis)
Schedules next retry.
-
setResponseTimeout
protected final boolean setResponseTimeout(ClientRequestContext ctx)
Resets theClientRequestContext.responseTimeoutMillis()
.- Returns:
true
if the response timeout is set,false
if it can't be set due to the timeout
-
getNextDelay
protected final long getNextDelay(ClientRequestContext ctx, Backoff backoff)
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
protected static int getTotalAttempts(ClientRequestContext ctx)
Returns the total number of attempts of the current request represented by the specifiedClientRequestContext
.
-
-