Class DataRateLimitedServlet

  • All Implemented Interfaces:, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class DataRateLimitedServlet
    extends javax.servlet.http.HttpServlet
    A servlet that uses the Servlet 3.1 asynchronous IO API to server static content at a limited data rate.

    Two implementations are supported:

    • The StandardDataStream impl uses only standard APIs, but produces more garbage due to the byte[] nature of the API.
    • the JettyDataStream impl uses a Jetty API to write a ByteBuffer and thus allow the efficient use of file mapped buffers without any temporary buffer copies (I did tell the JSR that this was a good idea to have in the standard!).

    The data rate is controlled by setting init parameters:

    The amount of data in bytes written per write
    The period in ms to wait after a write before attempting another
    The size of the thread pool used to service the writes (defaults to available processors)
    Thus if buffersize = 1024 and pause = 100, the data rate will be limited to 10KB per second.
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()  
      protected void doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      void init()  
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
      • Methods inherited from class javax.servlet.GenericServlet

        getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DataRateLimitedServlet

        public DataRateLimitedServlet()
    • Method Detail

      • init

        public void init()
                  throws javax.servlet.ServletException
        init in class javax.servlet.GenericServlet
      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Servlet
        destroy in class javax.servlet.GenericServlet
      • doGet

        protected void doGet​(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws javax.servlet.ServletException,
        doGet in class javax.servlet.http.HttpServlet