| java.lang.Object org.savarese.barehttp.HTTPServer
HTTPServer | public class HTTPServer (Code) | | Implements a server that listens for incoming client connections
and services each with
HTTPSession instances. A port
number, bind address, and maximum number of client connections to
service may be specified.
author: Daniel F. Savarese |
Method Summary | |
synchronized int | decrementConnectionCount() | public InetAddress | getBindAddress() Returns the network interface address the server will bind to. | public synchronized InetAddress | getBoundAddress() If the server is running, returns the address currently bound
to. | public synchronized int | getBoundPort() If the server is running, returns the port number currently bound
to. | public synchronized int | getConnectionCount() Returns the number of client connections currently established. | public String | getDocumentRoot() Returns the document root directory pathname. | public int | getMaxConnections() Returns the maximum number of concurrent client connections that
will be accepted. | public int | getPort() The port number the server will bind to. | synchronized int | incrementConnectionCount() | public synchronized boolean | isRunning() Returns true if the server is in a running state, false if not. | public synchronized void | setBindAddress(InetAddress bindAddr) Sets the network interface address the server should bind to. | public synchronized void | setMaxConnections(int maxConnections) Sets the maximum number of concurrent client connections the
server should accept. | public synchronized void | setPort(int port) Sets the port number the server should bind to. | public synchronized void | start() Starts listening for incoming connectons in an asynchronously
initiated thread. | public synchronized boolean | stop(long timeout, TimeUnit unit) Schedules termination of the server, closes the server socket,
and waits for the specified amount of time or until the server is
terminated before returning.
Parameters: timeout - The maximum amount of time to wait for termination. Parameters: unit - The unit of time for the timeout. |
DEFAULT_MAX_CONNECTIONS | final public static int DEFAULT_MAX_CONNECTIONS(Code) | | The default maximum number of concurrent client connections (10)
that will be accepted if not specified.
|
DEFAULT_PORT | final public static int DEFAULT_PORT(Code) | | The default port number (8080) to bind to if not specified.
|
httpPortmaxConnectionsbacklogconnectionCount | int httpPortmaxConnectionsbacklogconnectionCount(Code) | | |
HTTPServer | public HTTPServer(String documentRoot)(Code) | | Same as HTTPServer(documentRoot, DEFAULT_PORT, DEFAULT_MAX_CONNECTIONS);
|
HTTPServer | public HTTPServer(String root, int port, int maxConnections)(Code) | | Creates an HTTPServer instance.
Parameters: root - The fully qualified document root directory pathname. Parameters: port - The port number the server should bind to. Parameters: maxConnections - The maximum number of client connections theserver should accept. |
decrementConnectionCount | synchronized int decrementConnectionCount()(Code) | | |
getBindAddress | public InetAddress getBindAddress()(Code) | | Returns the network interface address the server will bind to. A
null return value signifies the wildcard address.
The network interface address the server will bind to. |
getBoundAddress | public synchronized InetAddress getBoundAddress()(Code) | | If the server is running, returns the address currently bound
to. Otherwise, returns null.
The port number currently bound to or -1 if not bound. |
getBoundPort | public synchronized int getBoundPort()(Code) | | If the server is running, returns the port number currently bound
to. Otherwise, returns -1.
The port number currently bound to or -1 if not bound. |
getConnectionCount | public synchronized int getConnectionCount()(Code) | | Returns the number of client connections currently established.
The number of client connections currently established. |
getDocumentRoot | public String getDocumentRoot()(Code) | | Returns the document root directory pathname.
The document root directory pathname. |
getMaxConnections | public int getMaxConnections()(Code) | | Returns the maximum number of concurrent client connections that
will be accepted.
The maximum number of concurrent client connections thatwill be accepted. |
getPort | public int getPort()(Code) | | The port number the server will bind to.
The port number the server will bind to. |
incrementConnectionCount | synchronized int incrementConnectionCount()(Code) | | |
isRunning | public synchronized boolean isRunning()(Code) | | Returns true if the server is in a running state, false if not.
True if the server is in a running state, false if not. |
setBindAddress | public synchronized void setBindAddress(InetAddress bindAddr)(Code) | | Sets the network interface address the server should bind to. By
default, the server binds to the wildcard address. The new bind
address takes effect the next time
HTTPServer.start is invoked
(after a
HTTPServer.stop if already running).
Parameters: bindAddr - The network interface the server should bind to.It may be null to reset to the wildcard. |
setMaxConnections | public synchronized void setMaxConnections(int maxConnections)(Code) | | Sets the maximum number of concurrent client connections the
server should accept.
Parameters: maxConnections - The maximum number of concurrent clientconnections the server should accept. |
setPort | public synchronized void setPort(int port)(Code) | | Sets the port number the server should bind to. By default, the
server binds to
HTTPServer.DEFAULT_PORT . The new port takes effect
the next time
HTTPServer.start is invoked (after a
HTTPServer.stop if
already running).
Parameters: port - The port number the server should bind to. |
start | public synchronized void start() throws IOException, IllegalStateException(Code) | | Starts listening for incoming connectons in an asynchronously
initiated thread. The method returns immediately after the
listening thread is established, making the HTTPServer instance
an active object.
throws: IOException - If the server socket cannot be bound. throws: IllegalStateException - If the server is already running. |
stop | public synchronized boolean stop(long timeout, TimeUnit unit) throws IOException(Code) | | Schedules termination of the server, closes the server socket,
and waits for the specified amount of time or until the server is
terminated before returning.
Parameters: timeout - The maximum amount of time to wait for termination. Parameters: unit - The unit of time for the timeout. True if the server terminated before the method returned,false if not. If false is returned, the server will not becompletely terminated untl HTTPServer.isRunning returns false.Subsequent calls to stop will have no effect while terminating. |
|
|