Class HttpServer


  • public class HttpServer
    extends Object
    • Field Detail

      • jmxManager

        protected volatile org.glassfish.grizzly.jmxbase.GrizzlyJmxManager jmxManager
      • managementObject

        protected volatile Object managementObject
    • Constructor Detail

      • HttpServer

        public HttpServer()
    • Method Detail

      • addListener

        public void addListener​(NetworkListener listener)

        Adds the specified listener to the server instance.

        If the server is already running when this method is called, the listener will be started.

        Parameters:
        listener - the NetworkListener to associate with this server instance.
      • removeListener

        public NetworkListener removeListener​(String name)

        Removes the NetworkListener associated with the specified name.

        If the server is running when this method is invoked, the listener will be stopped before being returned.

        Parameters:
        name - the name of the NetworkListener to remove.
        Returns:
        NetworkListener, that has been removed, or null if the listener with the given name doesn't exist
      • start

        public void start()
                   throws IOException

        Starts the HttpServer.

        Throws:
        IOException - if an error occurs while attempting to start the server.
      • getHttpHandler

        public HttpHandler getHttpHandler()
        Returns:
        the HttpHandler used by this HttpServer instance.
      • isStarted

        public boolean isStarted()
        Returns:
        true if this HttpServer has been started.
      • getManagementObject

        public Object getManagementObject​(boolean clear)
      • shutdown

        public org.glassfish.grizzly.GrizzlyFuture<HttpServer> shutdown​(long gracePeriod,
                                                                        TimeUnit timeUnit)
      • shutdown

        public org.glassfish.grizzly.GrizzlyFuture<HttpServer> shutdown()

        Gracefully shuts down the HttpServer instance.

      • shutdownNow

        public void shutdownNow()

        Immediately shuts down the HttpServer instance.

      • createSimpleServer

        public static HttpServer createSimpleServer​(String docRoot,
                                                    int port)
        Parameters:
        docRoot - the document root, can be null when no static pages are needed
        port - the network port to which this listener will bind
        Returns:
        a HttpServer configured to listen to requests on NetworkListener.DEFAULT_NETWORK_HOST:port, using the specified docRoot as the server's document root
      • createSimpleServer

        public static HttpServer createSimpleServer​(String docRoot,
                                                    org.glassfish.grizzly.PortRange range)
        Parameters:
        docRoot - the document root, can be null when no static pages are needed
        range - port range to attempt to bind to
        Returns:
        a HttpServer configured to listen to requests on NetworkListener.DEFAULT_NETWORK_HOST:[port-range], using the specified docRoot as the server's document root
      • createSimpleServer

        public static HttpServer createSimpleServer​(String docRoot,
                                                    SocketAddress socketAddress)
        Parameters:
        docRoot - the document root, can be null when no static pages are needed
        socketAddress - the endpoint address to which this listener will bind
        Returns:
        a HttpServer configured to listen to requests on socketAddress, using the specified docRoot as the server's document root
      • createSimpleServer

        public static HttpServer createSimpleServer​(String docRoot,
                                                    String host,
                                                    int port)
        Parameters:
        docRoot - the document root, can be null when no static pages are needed
        host - the network port to which this listener will bind
        port - the network port to which this listener will bind
        Returns:
        a HttpServer configured to listen to requests on host:port, using the specified docRoot as the server's document root
      • createSimpleServer

        public static HttpServer createSimpleServer​(String docRoot,
                                                    String host,
                                                    org.glassfish.grizzly.PortRange range)
        Parameters:
        docRoot - the document root, can be null when no static pages are needed
        host - the network port to which this listener will bind
        range - port range to attempt to bind to
        Returns:
        a HttpServer configured to listen to requests on host:[port-range], using the specified docRoot as the server's document root
      • enableJMX

        protected void enableJMX()
      • disableJMX

        protected void disableJMX()
      • configureCompressionEncodings

        protected Set<org.glassfish.grizzly.http.ContentEncoding> configureCompressionEncodings​(NetworkListener listener)