Class NetworkConnectionLimit

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

public class NetworkConnectionLimit extends AbstractLifeCycle implements 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
      Description copied from class: AbstractLifeCycle
      Method to override to start the lifecycle
      Overrides:
      doStart in class AbstractLifeCycle
      Throws:
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • doStop

      protected void doStop() throws Exception
      Description copied from class: AbstractLifeCycle
      Method to override to stop the lifecycle
      Overrides:
      doStop in class AbstractLifeCycle
      Throws:
      Exception - If there was a problem stopping. Will cause a transition to FAILED state
    • limit

      protected void limit()
    • unlimit

      protected void unlimit()
    • onAccepting

      public void onAccepting(SelectableChannel channel)
      Description copied from interface: SelectorManager.AcceptListener
      Called immediately after a new SelectableChannel is accepted, but before it has been submitted to the SelectorManager.
      Specified by:
      onAccepting in interface SelectorManager.AcceptListener
      Parameters:
      channel - the accepted channel
    • onAcceptFailed

      public void onAcceptFailed(SelectableChannel channel, Throwable cause)
      Description copied from interface: SelectorManager.AcceptListener
      Called if the processing of the accepted channel fails prior to calling SelectorManager.AcceptListener.onAccepted(SelectableChannel).
      Specified by:
      onAcceptFailed in interface SelectorManager.AcceptListener
      Parameters:
      channel - the accepted channel
      cause - the cause of the failure
    • onAccepted

      public void onAccepted(SelectableChannel channel)
      Description copied from interface: SelectorManager.AcceptListener
      Called after the accepted channel has been allocated an EndPoint and associated Connection, and after the onOpen notifications have been called on both endPoint and connection.
      Specified by:
      onAccepted in interface SelectorManager.AcceptListener
      Parameters:
      channel - the accepted channel
    • onClosed

      public void onClosed(SelectableChannel channel)
      Description copied from interface: SelectorManager.AcceptListener
      Called when an accepted SelectableChannel is closed.
      Specified by:
      onClosed in interface SelectorManager.AcceptListener
      Parameters:
      channel - the accepted channel