|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.w3c.jigsaw.http.Client
public abstract class Client
Client instances keep track of a specific connection with a browser. This abstract class is responsible for handling an HTTP connection, as described by an input and output stream, from right after the connection is accepted, until the connection has to be shutdown. It provides all the methods to run the HTTP dialog, and leave it to subclasses to implement the accept connection and the persistent connections strategy.
Customizing this class is done by subclassing it, and implementing the abstract methods.
For sample implementations, you can check the socket and mux sub packages.
ClientFactory
,
SocketClient
,
MuxClient
Field Summary | |
---|---|
protected byte[] |
buffer
The buffer used to emit copy data back to the client. |
protected boolean |
cont
flags to avoid multiple 100-Continue during multiple stages of a request |
java.net.URL |
currentURI
the current URI |
protected boolean |
debug
Is this client in debug mode ? |
protected int |
identifier
The uniq integer identifier for that client. |
protected long |
prev_body_count
The number of bytes in the body of the previously handled request |
protected int |
reqcount
Number of requests handled within this client context. |
protected httpd |
server
The server context responsible for that client. |
Constructor Summary | |
---|---|
Client()
|
Method Summary | |
---|---|
protected int |
chunkTransfer(java.io.InputStream is,
Reply reply)
Run chunk encoding on the provided stream to emit reply's body. |
protected int |
emitReply(Reply reply)
Emit the given reply to the client. |
void |
error(java.lang.String msg)
Emit an error message on behalf of that client. |
int |
getIdentifier()
Get this client identifier. |
abstract java.net.InetAddress |
getInetAddress()
Get the IP address of the host that runs the client described by this context. |
java.io.InputStream |
getInputStream()
Get this client input stream. |
short |
getMajorVersion()
Get the HTTP major version number spoken on the current connection. |
short |
getMinorVersion()
Get the HTTP minor version number spoken on the current connection. |
protected Request |
getNextRequest()
Read the next request from our current input stream. |
java.io.DataOutputStream |
getOutputStream()
Get this client output stream. |
int |
getRequestCount()
Get the total number of requests handled within this client context. |
httpd |
getServer()
Get the server context responsible for this client context. |
protected abstract java.lang.Thread |
getThread()
Get the thread powering that client, if any. |
void |
handleTimerEvent(java.lang.Object data,
long time)
Handle timer events. |
protected abstract boolean |
idleConnection()
Client callback - The client is about to block, getting next request. |
protected void |
initialize(httpd server,
int identifier)
Initialize this client. |
protected void |
interruptConnection(boolean now)
Interrupt the currently handled connection. |
boolean |
isInterrupted()
Does this client has an interrupt pending ? |
boolean |
isRunning()
Is this client currently running for a connection. |
void |
log(Request request,
Reply reply,
int nbytes,
long duration)
Log the given HTTP transaction. |
protected Reply |
processRequest(Request request)
Process a request. |
int |
sendContinue()
Send a 100 HTTP continue message on the currently handled connection. |
int |
sendContinue(Reply contReply)
Send a 100 HTTP continue message on the currently handled connection. |
protected boolean |
startConnection(java.io.InputStream in,
java.io.DataOutputStream out)
Start processing the given connection. |
protected abstract void |
stopConnection()
Client callback - The current connection has been terminated. |
void |
trace(java.lang.String msg)
Emit a trace on behalf of the given client. |
protected boolean |
tryKeepConnection(Request request,
Reply reply)
Request has been processed into Reply, should we keep connection alive ? Test wether we can keep the connection alive, after the given reply has been emited. |
protected abstract void |
usedConnection()
Client callback - A full request has been received on input stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int identifier
protected httpd server
protected boolean debug
protected byte[] buffer
protected int reqcount
protected boolean cont
protected long prev_body_count
public java.net.URL currentURI
Constructor Detail |
---|
public Client()
Method Detail |
---|
public void handleTimerEvent(java.lang.Object data, long time)
handleTimerEvent
in interface EventHandler
data
- The timer closure.time
- The absolute time at which the event was triggered.EventManager
,
EventHandler
protected boolean tryKeepConnection(Request request, Reply reply)
request
- The request to examine.reply
- Its computed reply.protected Request getNextRequest() throws ClientException, java.io.IOException
java.io.IOException
- If some IO error occured.
ClientException
- If either an IO error happened or bad
HTTP was received. In both cases the connection needs to be closed.protected int chunkTransfer(java.io.InputStream is, Reply reply) throws java.io.IOException
is
- The reply's body that has to be chunk encoded.
java.io.IOException
- If IO error occurs.protected int emitReply(Reply reply) throws java.io.IOException
reply
- The reply to be emited.
java.io.IOException
- If some IO error occurs.protected Reply processRequest(Request request) throws ClientException
request
- The request to process.
ClientException
- If either the timeout expires or the entity
was unable to handle the request.protected boolean startConnection(java.io.InputStream in, java.io.DataOutputStream out) throws ClientException
Before this method returns, both provided streams are always
closed, and the stopConnection
method invoked.
in
- The input stream to receive HTTP requests.out
- The output stream to send HTTP replies.
ClientException
- If some severe error has occured and the
current connection needs to be terminated.protected void interruptConnection(boolean now)
now
- Make sure the thread is interrupted right now if
true, otherwise, just schedule an interruption
after the current request (if any) has been processed.public int sendContinue() throws java.io.IOException
java.io.IOException
- If some IO error occured.public int sendContinue(Reply contReply) throws java.io.IOException
java.io.IOException
- If some IO error occured.public final int getIdentifier()
public final boolean isRunning()
public final short getMajorVersion()
public final short getMinorVersion()
public final boolean isInterrupted()
public final int getRequestCount()
public final httpd getServer()
public final void error(java.lang.String msg)
msg
- The error message to output.public final void trace(java.lang.String msg)
msg
- The trace to output.public void log(Request request, Reply reply, int nbytes, long duration)
request
- The request that has been processed.reply
- The generated reply.nbytes
- Number of content bytes sent along with the reply.duration
- The processing time for that request in milliseconds.public java.io.InputStream getInputStream()
public java.io.DataOutputStream getOutputStream()
public abstract java.net.InetAddress getInetAddress()
protected abstract boolean idleConnection()
startConnection
time.
protected abstract void usedConnection()
protected abstract void stopConnection()
startConnection
time, it is now stopped.
protected abstract java.lang.Thread getThread()
protected void initialize(httpd server, int identifier)
server
- The server responsible for that client.factory
- The factory that created this client.identifier
- The uniq identifier for this client.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |