| java.lang.Object java.lang.Thread sunlabs.brazil.server.Server
Server | public class Server extends Thread (Code) | | Yet another HTTP/1.1 server.
This class is the core of a light weight Web Server. This server
is started as a Thread listening on the supplied port, and
dispatches to an implementation of
a
Handler to service http requests. If no handler is
supplied, then the
FileHandler is used.
A
ChainHandler is provided to allow multiple handlers in one server.
Limitations:
- Starts a new thread for each connection. This may be expensive.
author: Stephen Uhler (stephen.uhler@sun.com) author: Colin Stevens (colin.stevens@sun.com) version: 1.35, 00/11/06 |
Field Summary | |
final public static int | LOG_DIAGNOSTIC | final public static int | LOG_ERROR | final public static int | LOG_INFORMATIONAL | final public static int | LOG_LOG | final public static int | LOG_WARNING | public int | acceptCount Count of accepted connections so far. | public int | bufsize Default buffer size for copies to and from client sockets. | public int | errorCount Count of errors that occurred so far. | ThreadGroup | group | public Handler | handler | public String | hostName The hostname that this Server should use to identify itself in
an HTTP Redirect. | public boolean | initFailure If set, the server will terminate with an initialization failure
just before creating the listen socket. | public ServerSocket | listen The listening socket. | public int | logLevel The diagnostic level. | public int | maxRequests Maximum number of consecutive requests allowed on a single
kept-alive socket. | public int | maxThreads | public String | name The string to return as the value for the "Server:" line in the HTTP
response header. | public String | prefix The handler is passed a prefix to identify which items in the
properties object are relevent. | public Properties | props Hashtable containing arbitrary information that may be of interest to
a Handler. | public String | protocol The protocol used to access this resource. | public int | requestCount Count of HTTP requests received so far. | public InetAddress[] | restrict If non-null, restrict connections to just the specified ip addresses. | public int | timeout Time in milliseconds before this Server closes an idle socket or
in-progress request. |
Method Summary | |
public void | close() | boolean | init() | public void | log(int level, Object obj, String message) Logs information about the socket to System.out . | public void | run() Loops, accepting socket connections and replying to HTTP requests.
This is called indirectly via Thread.start().
Many things in the server are not initialized until this point,
because the user may have set some related configuration options
between the time this server was allocated and the time it was
started. | public boolean | setup(ServerSocket listen, String handlerName, Properties props) |
LOG_DIAGNOSTIC | final public static int LOG_DIAGNOSTIC(Code) | | |
LOG_ERROR | final public static int LOG_ERROR(Code) | | |
LOG_INFORMATIONAL | final public static int LOG_INFORMATIONAL(Code) | | |
LOG_LOG | final public static int LOG_LOG(Code) | | |
LOG_WARNING | final public static int LOG_WARNING(Code) | | |
acceptCount | public int acceptCount(Code) | | Count of accepted connections so far.
|
bufsize | public int bufsize(Code) | | Default buffer size for copies to and from client sockets.
|
errorCount | public int errorCount(Code) | | Count of errors that occurred so far.
|
hostName | public String hostName(Code) | | The hostname that this Server should use to identify itself in
an HTTP Redirect. If null , the hostname is derived
by calling InetAddress.getHostAddress .
InetAddress.getHostName would generally be the wrong
thing to return because it returns only the base machine name
xxx and not the machine name as it needs to appear
to the rest of the network, such as xxx.yyy.com .
The default value is null .
|
initFailure | public boolean initFailure(Code) | | If set, the server will terminate with an initialization failure
just before creating the listen socket.
|
listen | public ServerSocket listen(Code) | | The listening socket. Every time a new socket is accepted,
a new thread is created to read the HTTP requests from it.
|
logLevel | public int logLevel(Code) | | The diagnostic level. 0->least, 5->most
|
maxRequests | public int maxRequests(Code) | | Maximum number of consecutive requests allowed on a single
kept-alive socket.
The default value is 25 .
|
maxThreads | public int maxThreads(Code) | | The max number of threads allowed for the entire VM
|
name | public String name(Code) | | The string to return as the value for the "Server:" line in the HTTP
response header. If null , then no "Server:" line is
returned.
|
prefix | public String prefix(Code) | | The handler is passed a prefix to identify which items in the
properties object are relevent. By convention, non-empty strings
end with ".", allowing nested prefixes to be easily distinguished.
|
protocol | public String protocol(Code) | | The protocol used to access this resource. Normally http , but
can be changed for ssl to https
|
requestCount | public int requestCount(Code) | | Count of HTTP requests received so far.
|
restrict | public InetAddress[] restrict(Code) | | If non-null, restrict connections to just the specified ip addresses.
The default value is null .
|
timeout | public int timeout(Code) | | Time in milliseconds before this Server closes an idle socket or
in-progress request.
The default value is 30000 .
|
Server | public Server(ServerSocket listen, String handlerName, Properties props)(Code) | | Create a server using the provided listener socket.
This server will call the Handler.respond method
of the specified handler. The specified handler should either
respond to the request or perform further dispatches to other
handlers.
Parameters: listen - The socket this server should listen to.For ordinary sockets, this is simply: new ServerSocket(port) , where port is the network port to listen on. Alternate implementationsof ServerSocket , such as ssl versionsmay be used instead. Parameters: handlerName - The name of the handler used to process http requests.It must implement the Handler interface. Parameters: props - Arbitrary information made available to the handler.May be null . See Also: FileHandler See Also: ChainHandler |
Server | public Server()(Code) | | Set up the server. this allows a server to be created with
newInstance() followed by setup(), instead of using the
above initializer, making it easier to start sub-classes
of the server.
|
close | public void close()(Code) | | Stop the server, and kill all pending requests
|
log | public void log(int level, Object obj, String message)(Code) | | Logs information about the socket to System.out .
Parameters: level - Controls the verbosity (0=least 5=most) Parameters: obj - The object that the message relates to. Parameters: message - The message to be logged. |
run | public void run()(Code) | | Loops, accepting socket connections and replying to HTTP requests.
This is called indirectly via Thread.start().
Many things in the server are not initialized until this point,
because the user may have set some related configuration options
between the time this server was allocated and the time it was
started. For instance, the main Handler is not
initialized until now, because its Handler.init method
may have wanted to examine server member variables such as
hostName or bufsize .
|
|
|