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.limit.AbstractConcurrencyLimitingClient<I,O>
- All Implemented Interfaces:
Client<I,O>
,Unwrappable
- Direct Known Subclasses:
ConcurrencyLimitingClient
public abstract class AbstractConcurrencyLimitingClient<I extends Request,O extends Response> extends SimpleDecoratingClient<I,O>
An abstract
Client
decorator that limits the concurrent number of active requests.
numActiveRequests()
increases when Client.execute(ClientRequestContext, Request)
is
invoked and decreases when the Response
returned by the
Client.execute(ClientRequestContext, Request)
is closed. When numActiveRequests()
reaches
at the configured maxConcurrency
the Request
s are deferred until the currently active
Request
s are completed.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConcurrencyLimitingClient(Client<I,O> delegate, int maxConcurrency)
Creates a new instance that decorates the specifieddelegate
to limit the concurrent number of active requests tomaxConcurrency
, with the default timeout of 10000L milliseconds.protected
AbstractConcurrencyLimitingClient(Client<I,O> delegate, int maxConcurrency, long timeout, TimeUnit unit)
Creates a new instance that decorates the specifieddelegate
to limit the concurrent number of active requests tomaxConcurrency
. -
Method Summary
Modifier and Type Method Description O
execute(ClientRequestContext ctx, I req)
protected abstract O
newDeferredResponse(ClientRequestContext ctx, CompletionStage<O> resFuture)
Implement this method to return a newResponse
which delegates to theResponse
the specifiedCompletionStage
is completed with.int
numActiveRequests()
Returns the number of theRequest
s that are being executed.Methods inherited from class com.linecorp.armeria.common.util.AbstractUnwrappable
as, delegate, toString
-
Constructor Details
-
AbstractConcurrencyLimitingClient
Creates a new instance that decorates the specifieddelegate
to limit the concurrent number of active requests tomaxConcurrency
, with the default timeout of 10000L milliseconds.- Parameters:
delegate
- the delegateClient
maxConcurrency
- the maximum number of concurrent active requests.0
to disable the limit.
-
AbstractConcurrencyLimitingClient
protected AbstractConcurrencyLimitingClient(Client<I,O> delegate, int maxConcurrency, long timeout, TimeUnit unit)Creates a new instance that decorates the specifieddelegate
to limit the concurrent number of active requests tomaxConcurrency
.- Parameters:
delegate
- the delegateClient
maxConcurrency
- the maximum number of concurrent active requests.0
to disable the limit.timeout
- the amount of time until this decorator fails the request if the request was not delegated to thedelegate
before then
-
-
Method Details
-
numActiveRequests
public int numActiveRequests()Returns the number of theRequest
s that are being executed. -
execute
Description copied from interface:Client
-
newDeferredResponse
protected abstract O newDeferredResponse(ClientRequestContext ctx, CompletionStage<O> resFuture) throws ExceptionImplement this method to return a newResponse
which delegates to theResponse
the specifiedCompletionStage
is completed with. For example, you could useHttpResponse.from(CompletionStage, EventExecutor)
:protected HttpResponse newDeferredResponse( ClientRequestContext ctx, CompletionStage<HttpResponse> resFuture) { return HttpResponse.from(resFuture, ctx.eventLoop()); }
- Throws:
Exception
-