|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.savarese.barehttp.HTTPServer
public class HTTPServer
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.
Field Summary | |
---|---|
static int |
DEFAULT_MAX_CONNECTIONS
The default maximum number of concurrent client connections (10) that will be accepted if not specified. |
static int |
DEFAULT_PORT
The default port number (8080) to bind to if not specified. |
Constructor Summary | |
---|---|
HTTPServer(java.lang.String documentRoot)
Same as HTTPServer(documentRoot, DEFAULT_PORT, DEFAULT_MAX_CONNECTIONS); |
|
HTTPServer(java.lang.String root,
int port,
int maxConnections)
Creates an HTTPServer instance. |
Method Summary | |
---|---|
java.net.InetAddress |
getBindAddress()
Returns the network interface address the server will bind to. |
java.net.InetAddress |
getBoundAddress()
If the server is running, returns the address currently bound to. |
int |
getBoundPort()
If the server is running, returns the port number currently bound to. |
int |
getConnectionCount()
Returns the number of client connections currently established. |
java.lang.String |
getDocumentRoot()
Returns the document root directory pathname. |
int |
getMaxConnections()
Returns the maximum number of concurrent client connections that will be accepted. |
int |
getPort()
The port number the server will bind to. |
boolean |
isRunning()
Returns true if the server is in a running state, false if not. |
void |
setBindAddress(java.net.InetAddress bindAddr)
Sets the network interface address the server should bind to. |
void |
setMaxConnections(int maxConnections)
Sets the maximum number of concurrent client connections the server should accept. |
void |
setPort(int port)
Sets the port number the server should bind to. |
void |
start()
Starts listening for incoming connectons in an asynchronously initiated thread. |
boolean |
stop(long timeout,
java.util.concurrent.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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_MAX_CONNECTIONS
public static final int DEFAULT_PORT
Constructor Detail |
---|
public HTTPServer(java.lang.String documentRoot)
public HTTPServer(java.lang.String root, int port, int maxConnections)
root
- The fully qualified document root directory pathname.port
- The port number the server should bind to.maxConnections
- The maximum number of client connections the
server should accept.Method Detail |
---|
public java.lang.String getDocumentRoot()
public void setPort(int port)
DEFAULT_PORT
. The new port takes effect
the next time start()
is invoked (after a stop(long, java.util.concurrent.TimeUnit)
if
already running).
port
- The port number the server should bind to.public int getPort()
public int getBoundPort()
public void setMaxConnections(int maxConnections)
maxConnections
- The maximum number of concurrent client
connections the server should accept.public int getMaxConnections()
public int getConnectionCount()
public void setBindAddress(java.net.InetAddress bindAddr)
start()
is invoked
(after a stop(long, java.util.concurrent.TimeUnit)
if already running).
bindAddr
- The network interface the server should bind to.
It may be null to reset to the wildcard.public java.net.InetAddress getBindAddress()
public java.net.InetAddress getBoundAddress()
public boolean isRunning()
public void start() throws java.io.IOException, java.lang.IllegalStateException
java.io.IOException
- If the server socket cannot be bound.
java.lang.IllegalStateException
- If the server is already running.public boolean stop(long timeout, java.util.concurrent.TimeUnit unit) throws java.io.IOException
timeout
- The maximum amount of time to wait for termination.unit
- The unit of time for the timeout.
isRunning()
returns false.
Subsequent calls to stop will have no effect while terminating.
java.io.IOException
|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |