public class HttpServer extends Object
Modifier and Type | Field and Description |
---|---|
protected GrizzlyJmxManager |
jmxManager |
protected Object |
managementObject |
Constructor and Description |
---|
HttpServer() |
protected volatile GrizzlyJmxManager jmxManager
protected volatile Object managementObject
public final ServerConfiguration getServerConfiguration()
ServerConfiguration
used to configure this
HttpServer
instancepublic 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.
listener
- the NetworkListener
to associate with this
server instance.public NetworkListener getListener(String name)
name
- the NetworkListener
name.NetworkListener
, if any, associated with the
specified name
.public Collection<NetworkListener> getListeners()
read only
Collection
over the listeners
associated with this HttpServer
instance.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.
name
- the name of the NetworkListener
to remove.NetworkListener
, that has been removed, or null
if the listener with the given name doesn't existpublic void start() throws IOException
Starts the HttpServer
.
IOException
- if an error occurs while attempting to start the
server.public HttpHandler getHttpHandler()
HttpHandler
used by this HttpServer
instance.public boolean isStarted()
true
if this HttpServer
has
been started.public Object getManagementObject(boolean clear)
public GrizzlyFuture<HttpServer> shutdown(long gracePeriod, TimeUnit timeUnit)
public GrizzlyFuture<HttpServer> shutdown()
Gracefully shuts down the HttpServer
instance.
public void shutdownNow()
Immediately shuts down the HttpServer
instance.
public void stop()
shutdownNow()
Immediately shuts down the HttpServer
instance.
public static HttpServer createSimpleServer()
HttpServer
configured to listen to requests
on NetworkListener.DEFAULT_NETWORK_HOST
:NetworkListener.DEFAULT_NETWORK_PORT
,
using the directory in which the server was launched the server's document rootpublic static HttpServer createSimpleServer(String docRoot)
docRoot
- the document root,
can be null
when no static pages are neededHttpServer
configured to listen to requests
on NetworkListener.DEFAULT_NETWORK_HOST
:NetworkListener.DEFAULT_NETWORK_PORT
,
using the specified docRoot
as the server's document rootpublic static HttpServer createSimpleServer(String docRoot, int port)
docRoot
- the document root,
can be null
when no static pages are neededport
- the network port to which this listener will bindHttpServer
configured to listen to requests
on NetworkListener.DEFAULT_NETWORK_HOST
:port
,
using the specified docRoot
as the server's document rootpublic static HttpServer createSimpleServer(String docRoot, PortRange range)
docRoot
- the document root,
can be null
when no static pages are neededrange
- port range to attempt to bind toHttpServer
configured to listen to requests
on NetworkListener.DEFAULT_NETWORK_HOST
:[port-range]
,
using the specified docRoot
as the server's document rootpublic static HttpServer createSimpleServer(String docRoot, SocketAddress socketAddress)
docRoot
- the document root,
can be null
when no static pages are neededsocketAddress
- the endpoint address to which this listener will bindHttpServer
configured to listen to requests
on socketAddress
,
using the specified docRoot
as the server's document rootpublic static HttpServer createSimpleServer(String docRoot, String host, int port)
docRoot
- the document root,
can be null
when no static pages are neededhost
- the network port to which this listener will bindport
- the network port to which this listener will bindHttpServer
configured to listen to requests
on host
:port
,
using the specified docRoot
as the server's document rootpublic static HttpServer createSimpleServer(String docRoot, String host, PortRange range)
docRoot
- the document root,
can be null
when no static pages are neededhost
- the network port to which this listener will bindrange
- port range to attempt to bind toHttpServer
configured to listen to requests
on host
:[port-range]
,
using the specified docRoot
as the server's document rootprotected void enableJMX()
protected void disableJMX()
protected Set<ContentEncoding> configureCompressionEncodings(NetworkListener listener)
Copyright © 2015 Oracle Corporation. All rights reserved.