This is basically a counter with a configured set of limits, that is used by RequestLimitingHandler.
When the number of active requests goes over the configured max requests then requests will be suspended and queued.
If the queue is full requests will be rejected with a 503 Service Unavailable according to RFC7231 Section 6.6.4.
The reason why this is abstracted out into a separate class is so that multiple handlers can share the same state. This allows for fine grained control of resources.
RequestLimitingHandler
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final ExchangeCompletionListener | |
| private volatile HttpHandler | failureHandler
The handler that will be invoked if the queue is full. |
| private volatile int | |
| private final Queue | |
| private volatile int | |
| private static final AtomicIntegerFieldUpdater |
| Access | Constructor and Description |
|---|---|
| public | |
| public | RequestLimit(int
the maximum concurrent requests maximumConcurrentRequests, int The maximum number of requests to queue queueSize)Construct a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public HttpHandler | |
| public int | Returns: the maximum concurrent requestsGet the maximum concurrent requests. |
| public void | |
| public void | |
| public int | setMaximumConcurrentRequests(int
the maximum concurrent requests newMax)Set the maximum concurrent requests. |
| COMPLETION_LISTENER | back to summary |
|---|---|
| private final ExchangeCompletionListener COMPLETION_LISTENER | |
| failureHandler | back to summary |
|---|---|
| private volatile HttpHandler failureHandler The handler that will be invoked if the queue is full. | |
| max | back to summary |
|---|---|
| private volatile int max | |
| queue | back to summary |
|---|---|
| private final Queue<RequestLimit. | |
| requests | back to summary |
|---|---|
private volatile int requests
| |
| requestsUpdater | back to summary |
|---|---|
| private static final AtomicIntegerFieldUpdater<RequestLimit> requestsUpdater | |
| RequestLimit | back to summary |
|---|---|
| public RequestLimit(int maximumConcurrentRequests) | |
| RequestLimit | back to summary |
|---|---|
| public RequestLimit(int maximumConcurrentRequests, int queueSize) Construct a new instance. The maximum number of concurrent requests must be at least one.
| |
| decrementRequests | back to summary |
|---|---|
| private void decrementRequests() | |
| getFailureHandler | back to summary |
|---|---|
| public HttpHandler getFailureHandler() | |
| getMaximumConcurrentRequests | back to summary |
|---|---|
| public int getMaximumConcurrentRequests() Get the maximum concurrent requests.
| |
| handleRequest | back to summary |
|---|---|
| public void handleRequest(final HttpServerExchange exchange, final HttpHandler next) throws Exception | |
| setFailureHandler | back to summary |
|---|---|
| public void setFailureHandler(HttpHandler failureHandler) | |
| setMaximumConcurrentRequests | back to summary |
|---|---|
| public int setMaximumConcurrentRequests(int newMax) Set the maximum concurrent requests. The value must be greater than or equal to one.
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final HttpServerExchange | |
| pack-priv final HttpHandler |
| Access | Constructor and Description |
|---|---|
| private |
| exchange | back to summary |
|---|---|
| pack-priv final HttpServerExchange exchange | |
| next | back to summary |
|---|---|
| pack-priv final HttpHandler next | |
| SuspendedRequest | back to summary |
|---|---|
| private SuspendedRequest(HttpServerExchange exchange, HttpHandler next) | |