Class AcceptRateLimit

  • All Implemented Interfaces:
    java.lang.Runnable, java.util.EventListener, SelectorManager.AcceptListener, LifeCycle

    @ManagedObject
    public class AcceptRateLimit
    extends AbstractLifeCycle
    implements SelectorManager.AcceptListener, java.lang.Runnable

    A Listener that limits the rate at which new connections are accepted

    If the limits are exceeded, accepting is suspended until the rate is again below the limit, so incoming connections are held in the operating system accept queue (no syn ack sent), where they may either timeout or wait for the server to resume accepting.

    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 AcceptLimit(100,5,TimeUnit.SECONDS,server));
       ...
       server.start();
     
    See Also:
    SelectorManager.AcceptListener
    • Constructor Detail

      • AcceptRateLimit

        public AcceptRateLimit​(@Name("acceptRateLimit")
                               int acceptRateLimit,
                               @Name("period")
                               long period,
                               @Name("units")
                               java.util.concurrent.TimeUnit units,
                               @Name("server")
                               Server server)
      • AcceptRateLimit

        public AcceptRateLimit​(@Name("limit")
                               int limit,
                               @Name("period")
                               long period,
                               @Name("units")
                               java.util.concurrent.TimeUnit units,
                               @Name("connectors")
                               Connector... connectors)
    • Method Detail

      • getAcceptRateLimit

        @ManagedAttribute("The accept rate limit")
        public int getAcceptRateLimit()
      • getUnits

        @ManagedAttribute("The accept rate period units")
        public java.util.concurrent.TimeUnit getUnits()
      • getMaxRate

        @ManagedAttribute("The maximum accept rate achieved")
        public long getMaxRate()
      • age

        protected void age​(long period,
                           java.util.concurrent.TimeUnit units)
      • doStart

        protected void doStart()
                        throws java.lang.Exception
        Overrides:
        doStart in class AbstractLifeCycle
        Throws:
        java.lang.Exception
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Overrides:
        doStop in class AbstractLifeCycle
        Throws:
        java.lang.Exception
      • limit

        protected void limit()
      • unlimit

        protected void unlimit()
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable