|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.w3c.www.protocol.http.HttpServer org.w3c.www.protocol.http.HttpBasicServer
public class HttpBasicServer
The basic server class, to run requests.
A server instance (ie an object conforming to the HttpServer
interface is resposnsible for running all requests to a given host.
To do so, it manages a connnnection pool (ie a set of available connections) which it negotiates with the global HTTP manager. It keeps track of the connections it creates in order to serialize requests to the target server (when possible). In order to avoid deadlock due to implicit ordering of requests, a server that manages persistent (ie > 1.0) connections will always be able to open at least two connections to the same target.
Connections are kept track of by the server instance, which maintains at all point in time a list of idle connections. The way this is done may seem quite tricky, but beleive me, it's the best way I have found to handle it (there is here a typical deadlock situation - the same which is found in org.w3c.jigsaw.http.Client - due to the fact that the server instances need to be locked in order to change the connection pool, and at the same time each connection of the pool might have to notify the pool of some events. This can easily produce a deadlock...This situation is avoided here, by having the server locked only when appropriate...
Field Summary | |
---|---|
protected int |
conn_timeout
The connectiontimeout for the socket |
protected int |
connid
Connections management - Allocate a new connection for this server. |
protected java.lang.String |
host
The host name of the server we handle. |
protected HttpManager |
manager
Our central HTTP manager. |
protected int |
port
The port number of the server we handle. |
protected static int |
RQ_HTTP10
Request mode - HTTP/1.0 with no keep-alive support. |
protected static int |
RQ_HTTP10_KA
Request mode - HTTP/1.0 with keep-alive support. |
protected static int |
RQ_HTTP11
Request mode - Full HTTP/1.1 compliant mode. |
protected static int |
RQ_HTTP11_TS
Request mode - Full two stage HTTP/1.1 compliant mode. |
protected static int |
RQ_UNKNOWN
Request mode - Unknown target server. |
protected int |
timeout
The timeout on the socket |
Fields inherited from class org.w3c.www.protocol.http.HttpServer |
---|
state |
Method Summary | |
---|---|
protected org.w3c.www.protocol.http.HttpBasicConnection |
allocateConnection()
|
void |
deleteConnection(org.w3c.www.protocol.http.HttpConnection conn)
|
protected Reply |
doRequest(org.w3c.www.protocol.http.HttpBasicConnection conn,
Request request)
Exceute given request on given conection, according to server. |
protected org.w3c.www.protocol.http.HttpBasicConnection |
getConnection()
Connections management - Get an idle connection to run a request. |
short |
getMajorVersion()
HttpServer implementation - Get this server's major version number. |
short |
getMinorVersion()
HttpServer implementation - Get this server's minor version number. |
java.lang.String |
getProtocol()
HttpServer implementation - Get this servers' protocol. |
protected int |
getRequestMode(Request request)
Get the current mode of running request for that server. |
protected Reply |
http_unknown(org.w3c.www.protocol.http.HttpBasicConnection conn,
Request request)
Run that request, we don't know what server we have at the other end. |
protected Reply |
http10_ka_run(org.w3c.www.protocol.http.HttpBasicConnection conn,
Request request)
Run an HTTP/1.0 request that has support for keep alive. |
protected Reply |
http10_run(org.w3c.www.protocol.http.HttpBasicConnection conn,
Request request)
Run a simple HTTP/1.0 request. |
protected Reply |
http11_run(org.w3c.www.protocol.http.HttpBasicConnection conn,
Request request)
Run a fully HTTP/1.1 compliant request. |
protected Reply |
http11_ts_run(org.w3c.www.protocol.http.HttpBasicConnection conn,
Request request)
Run a two stage HTTP/1.1 compliant request. |
void |
initialize(HttpManager manager,
org.w3c.www.protocol.http.HttpServerState state,
java.lang.String host,
int port,
int timeout)
HttpServer implementation - Initialize this server to its target. |
void |
initialize(HttpManager manager,
org.w3c.www.protocol.http.HttpServerState state,
java.lang.String host,
int port,
int timeout,
int conn_timeout)
HttpServer implementation - Initialize this server to its target. |
protected void |
interruptRequest(Request request)
Interrupt given request, that was launched by ourself. |
protected boolean |
isTwoStage_10(Request request)
Is this request a two stage request. |
protected boolean |
isTwoStage_11(Request request)
Is this request a two stage request. |
protected void |
notifyObserver(RequestObserver obs,
RequestEvent evt)
|
protected void |
notifyObserver(RequestObserver obs,
Request request,
int code)
|
void |
registerConnection(org.w3c.www.protocol.http.HttpConnection conn)
Connections management - Register a connection as being idle. |
Reply |
runRequest(Request request)
Run the given request in synchronous mode. |
void |
setConnTimeout(int conn_timeout)
Set the connection timeout for the next connections |
protected void |
setHostAddr(java.net.InetAddress[] hostAddrs)
set the inet addresses of this host, and timestamp it to avoid caching IPs forever |
void |
setTimeout(int timeout)
Set the timeout for the next connections |
java.lang.String |
toString()
Display this server into a String. |
void |
unregisterConnection(org.w3c.www.protocol.http.HttpConnection conn)
Unregister a connection from the idle list. |
protected void |
updateHostAddr()
check the validity of the host address if invalid, it will update the InetAddress associated with this host |
protected void |
updateServerInfo(Reply reply)
A full round-trip has been run with the target server, update infos. |
Methods inherited from class org.w3c.www.protocol.http.HttpServer |
---|
getState |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final int RQ_HTTP11
protected static final int RQ_HTTP11_TS
protected static final int RQ_HTTP10
protected static final int RQ_HTTP10_KA
protected static final int RQ_UNKNOWN
protected HttpManager manager
protected java.lang.String host
protected int port
protected int timeout
protected int conn_timeout
protected int connid
Method Detail |
---|
protected void setHostAddr(java.net.InetAddress[] hostAddrs)
hostAddrs,
- an array of InetAddressprotected void updateHostAddr() throws HttpException
HttpException
public java.lang.String getProtocol()
getProtocol
in class HttpServer
public short getMajorVersion()
getMajorVersion
in class HttpServer
public short getMinorVersion()
getMinorVersion
in class HttpServer
public void setTimeout(int timeout)
setTimeout
in class HttpServer
timeout
- The timeout in millisecondspublic void setConnTimeout(int conn_timeout)
setConnTimeout
in class HttpServer
timeout
- The timeout in millisecondsprotected org.w3c.www.protocol.http.HttpBasicConnection allocateConnection() throws java.io.IOException
java.io.IOException
public void registerConnection(org.w3c.www.protocol.http.HttpConnection conn)
conn
- The connection that is now idle.public void unregisterConnection(org.w3c.www.protocol.http.HttpConnection conn)
conn
- The connection to unregister from the idle list.public void deleteConnection(org.w3c.www.protocol.http.HttpConnection conn)
protected org.w3c.www.protocol.http.HttpBasicConnection getConnection() throws java.io.IOException
This method can return null to indicate to the caller that it should try again, in the hope that the target server has multiple (different) IP addresses.
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
protected void updateServerInfo(Reply reply)
reply
- The first reply we got from this server.public void initialize(HttpManager manager, org.w3c.www.protocol.http.HttpServerState state, java.lang.String host, int port, int timeout) throws HttpException
initialize
in class HttpServer
manager
- The central HTTP manager.state
- The manager's state for that server.host
- The target server's host name.port
- The target server's port number.timeout
- The timeout for the connection handled by the server
HttpException
- If the server host couldn't be resolved
to one or more IP addresses.public void initialize(HttpManager manager, org.w3c.www.protocol.http.HttpServerState state, java.lang.String host, int port, int timeout, int conn_timeout) throws HttpException
initialize
in class HttpServer
manager
- The central HTTP manager.state
- The manager's state for that server.host
- The target server's host name.port
- The target server's port number.timeout
- The timeout for the connection handled by the servertimeout
- The connection timeout in millisecond for the sockets
HttpException
- If the server host couldn't be resolved
to one or more IP addresses.protected void notifyObserver(RequestObserver obs, Request request, int code)
protected void notifyObserver(RequestObserver obs, RequestEvent evt)
protected boolean isTwoStage_10(Request request)
protected boolean isTwoStage_11(Request request)
protected int getRequestMode(Request request)
protected Reply http11_run(org.w3c.www.protocol.http.HttpBasicConnection conn, Request request) throws java.io.IOException, MimeParserException
conn
- The connection to run the request on.request
- The request to run.
java.io.IOException
- If some IO error occured.
MimeParserException
- If some MIME parsing error occured.protected Reply http11_ts_run(org.w3c.www.protocol.http.HttpBasicConnection conn, Request request) throws java.io.IOException, MimeParserException
conn
- The connection to run the request on.request
- The request to run.
java.io.IOException
- If some IO error occured.
MimeParserException
- If some MIME parsing error occured.protected Reply http10_ka_run(org.w3c.www.protocol.http.HttpBasicConnection conn, Request request) throws java.io.IOException, MimeParserException
conn
- The connection to run the request on.request
- The request to run.
java.io.IOException
- If some IO error occured.
MimeParserException
- If some MIME parsing error occured.protected Reply http10_run(org.w3c.www.protocol.http.HttpBasicConnection conn, Request request) throws java.io.IOException, MimeParserException
That's cool !
conn
- The connection to run the request on.request
- The request to run.
java.io.IOException
- If some IO error occured.
MimeParserException
- If some MIME parsing error occured.protected Reply http_unknown(org.w3c.www.protocol.http.HttpBasicConnection conn, Request request) throws java.io.IOException, MimeParserException
http10_run
and update the server infos by the end of processing.
conn
- The connection to run the request on.request
- The request to run.
java.io.IOException
- If some IO error occured.
MimeParserException
- If some MIME parsing error occured.protected Reply doRequest(org.w3c.www.protocol.http.HttpBasicConnection conn, Request request) throws java.io.IOException, MimeParserException
conn
- The connection to use to run that request.request
- The request to execute.
java.io.IOException
- If some IO error occurs, or if the
request is interrupted.
MimeParserException
- If taregt server doesn't conform to
the HTTP specification.protected void interruptRequest(Request request)
interruptRequest
in class HttpServer
request
- The request to interrupt.public Reply runRequest(Request request) throws HttpException
runRequest
in class HttpServer
request
- The request to run.
HttpException
- If the request processing failed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |