Class ConnectionLimit

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

@ManagedObject public class ConnectionLimit extends org.eclipse.jetty.util.component.AbstractLifeCycle implements org.eclipse.jetty.io.Connection.Listener, org.eclipse.jetty.io.SelectorManager.AcceptListener

A Listener that limits the number of Connections.

This listener applies a limit to the number of connections, which when exceeded results in a call to AbstractConnector.setAccepting(boolean) to prevent further connections being received. It can be applied to an entire server or to a specific connector by adding it via Container.addBean(Object)

Usage:

   Server server = new Server();
   server.addBean(new ConnectionLimit(5000,server));
   ...
   server.start();
 
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException

    Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection.Listener

    org.eclipse.jetty.io.Connection.Listener.Adapter

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, STARTED, STARTING, STOPPED, STOPPING
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConnectionLimit(int maxConnections, Connector... connectors)
     
    ConnectionLimit(int maxConnections, Server server)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
     
    protected void
     
    int
     
    long
     
    int
     
    protected void
     
    void
     
    void
     
    void
     
    void
    onClosed(org.eclipse.jetty.io.Connection connection)
     
    void
    onOpened(org.eclipse.jetty.io.Connection connection)
     
    void
    setIdleTimeout(long idleTimeout)
     
    void
     
    protected void
     

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    addEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, start, stop, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ConnectionLimit

      public ConnectionLimit(@Name("maxConnections") int maxConnections, @Name("server") Server server)
    • ConnectionLimit

      public ConnectionLimit(@Name("maxConnections") int maxConnections, @Name("connectors") Connector... connectors)
  • Method Details

    • getIdleTimeout

      @ManagedAttribute("The endpoint idle timeout in ms to apply when the connection limit is reached") public long getIdleTimeout()
      Returns:
      If >= 0, the endpoint idle timeout in ms to apply when the connection limit is reached
    • setIdleTimeout

      public void setIdleTimeout(long idleTimeout)
      Parameters:
      idleTimeout - If >= 0 the endpoint idle timeout in ms to apply when the connection limit is reached
    • getMaxConnections

      @ManagedAttribute("The maximum number of connections allowed") public int getMaxConnections()
    • setMaxConnections

      public void setMaxConnections(int max)
    • getConnections

      @ManagedAttribute("The current number of connections ") public int getConnections()
    • 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
    • check

      protected void check()
    • 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
    • onOpened

      public void onOpened(org.eclipse.jetty.io.Connection connection)
      Specified by:
      onOpened in interface org.eclipse.jetty.io.Connection.Listener
    • onClosed

      public void onClosed(org.eclipse.jetty.io.Connection connection)
      Specified by:
      onClosed in interface org.eclipse.jetty.io.Connection.Listener