sunlabs.brazil.server
public class Server extends Thread
Limitations:
Version: 2.4
Field Summary | |
---|---|
int | acceptCount
Count of accepted connections so far. |
int | bufsize
Default buffer size for copies to and from client sockets.
(default is 8192) |
int | errorCount
Count of errors that occurred so far. |
Handler | handler |
String | hostName
The hostname that this Server should use to identify itself in
an HTTP Redirect. |
boolean | initFailure
If set, the server will terminate with an initialization failure
just before creating the listen socket. |
ServerSocket | listen
The listening socket. |
int | logLevel
The diagnostic level. |
static int | LOG_DIAGNOSTIC |
static int | LOG_ERROR |
static int | LOG_INFORMATIONAL |
static int | LOG_LOG |
static int | LOG_WARNING |
int | maxPost
Maximum amout of POST data allowed per request (in bytes)
(default = 2Meg). |
int | maxRequests
Maximum number of consecutive requests allowed on a single
kept-alive socket.
|
int | maxThreads
The max number of threads allowed for the entire VM
(default is 250). |
String | name
The string to return as the value for the "Server:" line in the HTTP
response header. |
String | prefix
The handler is passed a prefix to identify which items in the
properties object are relevent. |
Properties | props
Hashtable containing arbitrary information that may be of interest to
a Handler. |
String | protocol
The protocol used to access this resource. |
int | requestCount
Count of HTTP requests received so far. |
InetAddress[] | restrict
If non-null, restrict connections to just the specified ip addresses.
|
int | timeout
Time in milliseconds before this Server closes an idle socket or
in-progress request.
|
Constructor Summary | |
---|---|
Server(ServerSocket listen, String handlerName, Properties props)
Create a server using the provided listener socket.
| |
Server()
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. |
Method Summary | |
---|---|
void | close()
Stop the server, and kill all pending requests |
boolean | init() |
void | log(int level, Object obj, String message)
Logs information about the socket to System.out .
|
boolean | restart(String newHandler)
Restart the server with a new handler. |
void | run()
Loops, accepting socket connections and replying to HTTP requests.
|
boolean | setup(ServerSocket listen, String handlerName, Properties props) |
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
.
The default value is 25
.
null
, then no "Server:" line is
returned.http
, but
can be changed for ssl
to https
The default value is null
.
The default value is 30000
.
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 implementations
of ServerSocket
, such as ssl versions
may be used instead. handlerName
The name of the handler used to process http requests.
It must implement the {@link Handler} interface. props
Arbitrary information made available to the handler.
May be null
.
See Also: FileHandler ChainHandler
System.out
.
Parameters: level Controls the verbosity (0=least 5=most) obj The object that the message relates to. message The message to be logged.
Parameters: newHandler Name of the handler to restart the server with
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
.