public abstract class ConcurrencyLimitingClient<I extends Request,O extends Response> extends SimpleDecoratingClient<I,O>
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 Requests are deferred until the currently active
Requests are completed.
| Modifier and Type | Class and Description |
|---|---|
static interface |
ConcurrencyLimitingClient.Deferred<O extends Response>
|
| Modifier | Constructor and Description |
|---|---|
protected |
ConcurrencyLimitingClient(Client<I,O> delegate,
int maxConcurrency)
Creates a new instance that decorates the specified
delegate to limit the concurrent number of
active requests to maxConcurrency, with the default timeout of
milliseconds. |
protected |
ConcurrencyLimitingClient(Client<I,O> delegate,
int maxConcurrency,
long timeout,
TimeUnit unit)
Creates a new instance that decorates the specified
delegate to limit the concurrent number of
active requests to maxConcurrency. |
| Modifier and Type | Method and Description |
|---|---|
protected abstract ConcurrencyLimitingClient.Deferred<O> |
defer(ClientRequestContext ctx,
I req)
Defers the specified
Request. |
O |
execute(ClientRequestContext ctx,
I req)
|
int |
numActiveRequests()
Returns the number of the
Requests that are being executed. |
as, delegate, toStringprotected ConcurrencyLimitingClient(Client<I,O> delegate, int maxConcurrency)
delegate to limit the concurrent number of
active requests to maxConcurrency, with the default timeout of
milliseconds.delegate - the delegate ClientmaxConcurrency - the maximum number of concurrent active requests. 0 to disable the limit.protected ConcurrencyLimitingClient(Client<I,O> delegate, int maxConcurrency, long timeout, TimeUnit unit)
delegate to limit the concurrent number of
active requests to maxConcurrency.delegate - the delegate ClientmaxConcurrency - 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 the delegate before thenpublic int numActiveRequests()
Requests that are being executed.public O execute(ClientRequestContext ctx, I req) throws Exception
Clientprotected abstract ConcurrencyLimitingClient.Deferred<O> defer(ClientRequestContext ctx, I req) throws Exception
Request.ConcurrencyLimitingClient.Deferred which provides the interface for updating the result of
Request execution later.ExceptionCopyright © 2020 LeanCloud. All rights reserved.