Class NetworkConnectionLimit

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.server.NetworkConnectionLimit
All Implemented Interfaces:
EventListener, org.eclipse.jetty.io.SelectorManager.AcceptListener, org.eclipse.jetty.io.SelectorManager.SelectorManagerListener, org.eclipse.jetty.util.component.LifeCycle

public class NetworkConnectionLimit extends org.eclipse.jetty.util.component.AbstractLifeCycle implements org.eclipse.jetty.io.SelectorManager.AcceptListener

A listener that limits the number of network connections.

This listener applies a limit to the number of network connections, which when exceeded results in a call to AbstractConnector.setAccepting(boolean) to prevent further network connections to be accepted.

This listener can be applied to an entire Server or to a specific Connector by adding it via Container.addBean(Object).

When the number of network connections is exceeded, the idle timeout of existing EndPoints is changed to the value configured in this listener (typically a shorter value). When the number of network connections returns below the limit, as they are closed, the idle timeout of existing EndPoints is restored to that of the connector.

Typical usage:

Server server = new Server();
server.addBean(new NetworkConnectionLimit(5000, server));
...
server.start();
See Also:
  • Constructor Details

    • NetworkConnectionLimit

      public NetworkConnectionLimit(@Name("maxNetworkConnectionCount") int maxNetworkConnections, @Name("server") Server server)
    • NetworkConnectionLimit

      public NetworkConnectionLimit(@Name("maxNetworkConnectionCount") int maxNetworkConnections, @Name("connectors") Connector... connectors)
  • Method Details

    • getEndPointIdleTimeout

      @ManagedAttribute("The EndPoint idle timeout in ms to apply when the network connection limit is reached") public long getEndPointIdleTimeout()
      Returns:
      the idle timeout in ms to apply to all EndPoints when the network connection limit is reached
    • setEndPointIdleTimeout

      public void setEndPointIdleTimeout(long idleTimeout)

      Sets the idle timeout in ms to apply to all EndPoints when the network connection limit is reached.

      A value less than or equal to zero will not change the existing EndPoint idle timeout.

      Parameters:
      idleTimeout - the idle timeout in ms to apply to all EndPoints when the network connection limit is reached
    • getMaxNetworkConnectionCount

      @ManagedAttribute("The maximum number of network connections") public int getMaxNetworkConnectionCount()
    • setMaxNetworkConnectionCount

      public void setMaxNetworkConnectionCount(int max)
    • getNetworkConnectionCount

      @ManagedAttribute("The number of connected network connections") public int getNetworkConnectionCount()
    • getPendingNetworkConnectionCount

      @ManagedAttribute("The number of pending network connections") public int getPendingNetworkConnectionCount()
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.eclipse.jetty.util.component.AbstractLifeCycle
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.eclipse.jetty.util.component.AbstractLifeCycle
      Throws:
      Exception
    • limit

      protected void limit()
    • unlimit

      protected void unlimit()
    • onAccepting

      public void onAccepting(SelectableChannel channel)
      Specified by:
      onAccepting in interface org.eclipse.jetty.io.SelectorManager.AcceptListener
    • onAcceptFailed

      public void onAcceptFailed(SelectableChannel channel, Throwable cause)
      Specified by:
      onAcceptFailed in interface org.eclipse.jetty.io.SelectorManager.AcceptListener
    • onAccepted

      public void onAccepted(SelectableChannel channel)
      Specified by:
      onAccepted in interface org.eclipse.jetty.io.SelectorManager.AcceptListener
    • onClosed

      public void onClosed(SelectableChannel channel)
      Specified by:
      onClosed in interface org.eclipse.jetty.io.SelectorManager.AcceptListener