Class RequestLimitingHandler

  • All Implemented Interfaces:
    HttpHandler

    public final class RequestLimitingHandler
    extends java.lang.Object
    implements HttpHandler
    A handler which limits the maximum number of concurrent requests. Requests beyond the limit will block until the previous request is complete.
    Author:
    David M. Lloyd
    • Constructor Detail

      • RequestLimitingHandler

        public RequestLimitingHandler​(int maximumConcurrentRequests,
                                      HttpHandler nextHandler)
        Construct a new instance. The maximum number of concurrent requests must be at least one. The next handler must not be null.
        Parameters:
        maximumConcurrentRequests - the maximum concurrent requests
        nextHandler - the next handler
      • RequestLimitingHandler

        public RequestLimitingHandler​(int maximumConcurrentRequests,
                                      int queueSize,
                                      HttpHandler nextHandler)
        Construct a new instance. The maximum number of concurrent requests must be at least one. The next handler must not be null.
        Parameters:
        maximumConcurrentRequests - the maximum concurrent requests
        queueSize - the maximum number of requests to queue
        nextHandler - the next handler
      • RequestLimitingHandler

        public RequestLimitingHandler​(RequestLimit requestLimit,
                                      HttpHandler nextHandler)
        Construct a new instance. This version takes a RequestLimit directly which may be shared with other handlers.
        Parameters:
        requestLimit - the request limit information.
        nextHandler - the next handler
    • Method Detail

      • handleRequest

        public void handleRequest​(HttpServerExchange exchange)
                           throws java.lang.Exception
        Description copied from interface: HttpHandler
        Handle the request.
        Specified by:
        handleRequest in interface HttpHandler
        Parameters:
        exchange - the HTTP request/response exchange
        Throws:
        java.lang.Exception