Class HttpServer


  • public class HttpServer
    extends java.lang.Object
    • Field Detail

      • managementObject

        protected volatile java.lang.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.
      • getListeners

        public java.util.Collection<NetworkListener> getListeners()
        Returns:
        a read only Collection over the listeners associated with this HttpServer instance.
      • removeListener

        public NetworkListener removeListener​(java.lang.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 java.io.IOException

        Starts the HttpServer.

        Throws:
        java.io.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 java.lang.Object getManagementObject​(boolean clear)
      • shutdown

        public GrizzlyFuture<HttpServer> shutdown​(long gracePeriod,
                                                  java.util.concurrent.TimeUnit timeUnit)
      • shutdownNow

        public void shutdownNow()

        Immediately shuts down the HttpServer instance.

      • stop

        @Deprecated
        public void stop()
        Deprecated.

        Immediately shuts down the HttpServer instance.

      • createSimpleServer

        public static HttpServer createSimpleServer​(java.lang.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​(java.lang.String docRoot,
                                                    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​(java.lang.String docRoot,
                                                    java.net.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​(java.lang.String docRoot,
                                                    java.lang.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​(java.lang.String docRoot,
                                                    java.lang.String host,
                                                    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()