- java.lang.Object
-
- com.linecorp.armeria.client.DecoratingClient<I,O,I,O>
-
- com.linecorp.armeria.client.SimpleDecoratingClient<I,O>
-
- com.linecorp.armeria.client.limit.ConcurrencyLimitingClient<I,O>
-
- All Implemented Interfaces:
Client<I,O>
- Direct Known Subclasses:
ConcurrencyLimitingHttpClient
public abstract class ConcurrencyLimitingClient<I extends Request,O extends Response> extends SimpleDecoratingClient<I,O>
An abstractClient
decorator that limits the concurrent number of active requests.numActiveRequests()
increases whenClient.execute(ClientRequestContext, Request)
is invoked and decreases when theResponse
returned by theClient.execute(ClientRequestContext, Request)
is closed. WhennumActiveRequests()
reaches at the configuredmaxConcurrency
theRequest
s are deferred until the currently activeRequest
s are completed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ConcurrencyLimitingClient.Deferred<O extends Response>
-
Constructor Summary
Constructors Modifier Constructor Description protected
ConcurrencyLimitingClient(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
ConcurrencyLimitingClient(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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract ConcurrencyLimitingClient.Deferred<O>
defer(ClientRequestContext ctx, I req)
Defers the specifiedRequest
.O
execute(ClientRequestContext ctx, I req)
int
numActiveRequests()
Returns the number of theRequest
s that are being executed.-
Methods inherited from class com.linecorp.armeria.client.DecoratingClient
delegate, toString
-
-
-
-
Constructor Detail
-
ConcurrencyLimitingClient
protected ConcurrencyLimitingClient(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.- Parameters:
delegate
- the delegateClient
maxConcurrency
- the maximum number of concurrent active requests.0
to disable the limit.
-
ConcurrencyLimitingClient
protected ConcurrencyLimitingClient(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 Detail
-
numActiveRequests
public int numActiveRequests()
Returns the number of theRequest
s that are being executed.
-
execute
public O execute(ClientRequestContext ctx, I req) throws Exception
Description copied from interface:Client
-
defer
protected abstract ConcurrencyLimitingClient.Deferred<O> defer(ClientRequestContext ctx, I req) throws Exception
Defers the specifiedRequest
.- Returns:
- a new
ConcurrencyLimitingClient.Deferred
which provides the interface for updating the result ofRequest
execution later. - Throws:
Exception
-
-