Top Description Inners Fields Constructors Methods
io.undertow.server.handlers

public Class RequestLimit

extends Object
Class Inheritance
Imports
io.undertow.UndertowLogger, io.undertow.server.Connectors, .ExchangeCompletionListener, .HttpHandler, .HttpServerExchange, io.undertow.util.SameThreadExecutor, java.util.Queue, java.util.concurrent.LinkedBlockingQueue, java.util.concurrent.atomic.AtomicIntegerFieldUpdater

Represents a limit on a number of running requests.

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.

Author
Stuart Douglas
See Also
RequestLimitingHandler

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField 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<RequestLimit.SuspendedRequest>
private volatile int
private static final AtomicIntegerFieldUpdater<RequestLimit>

Constructor Summary

AccessConstructor and Description
public
RequestLimit(int maximumConcurrentRequests)

public
RequestLimit(int
the maximum concurrent requests
maximumConcurrentRequests
,
int
The maximum number of requests to queue
queueSize
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
private void
public HttpHandler
public int

Returns:

the maximum concurrent requests
getMaximumConcurrentRequests
()

Get the maximum concurrent requests.

public void
handleRequest(final HttpServerExchange exchange, final HttpHandler next)

public void
public int
setMaximumConcurrentRequests(int
the maximum concurrent requests
newMax
)

Set the maximum concurrent requests.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COMPLETION_LISTENERback to summary
private final ExchangeCompletionListener COMPLETION_LISTENER
failureHandlerback to summary
private volatile HttpHandler failureHandler

The handler that will be invoked if the queue is full.

maxback to summary
private volatile int max
queueback to summary
private final Queue<RequestLimit.SuspendedRequest> queue
requestsback to summary
private volatile int requests
Annotations
@SuppressWarnings:unused
requestsUpdaterback to summary
private static final AtomicIntegerFieldUpdater<RequestLimit> requestsUpdater

Constructor Detail

RequestLimitback to summary
public RequestLimit(int maximumConcurrentRequests)
RequestLimitback to summary
public RequestLimit(int maximumConcurrentRequests, int queueSize)

Construct a new instance. The maximum number of concurrent requests must be at least one.

Parameters
maximumConcurrentRequests:int

the maximum concurrent requests

queueSize:int

The maximum number of requests to queue

Method Detail

decrementRequestsback to summary
private void decrementRequests()
getFailureHandlerback to summary
public HttpHandler getFailureHandler()
getMaximumConcurrentRequestsback to summary
public int getMaximumConcurrentRequests()

Get the maximum concurrent requests.

Returns:int

the maximum concurrent requests

handleRequestback to summary
public void handleRequest(final HttpServerExchange exchange, final HttpHandler next) throws Exception
setFailureHandlerback to summary
public void setFailureHandler(HttpHandler failureHandler)
setMaximumConcurrentRequestsback to summary
public int setMaximumConcurrentRequests(int newMax)

Set the maximum concurrent requests. The value must be greater than or equal to one.

Parameters
newMax:int

the maximum concurrent requests

io.undertow.server.handlers back to summary

private final Class RequestLimit.SuspendedRequest

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final HttpServerExchange
pack-priv final HttpHandler

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

exchangeback to summary
pack-priv final HttpServerExchange exchange
nextback to summary
pack-priv final HttpHandler next

Constructor Detail

SuspendedRequestback to summary
private SuspendedRequest(HttpServerExchange exchange, HttpHandler next)