| java.lang.Object HTTPClient.StreamDemultiplexor
StreamDemultiplexor | class StreamDemultiplexor implements GlobalConstants(Code) | | This class handles the demultiplexing of input stream. This is needed
for things like keep-alive in HTTP/1.0, persist in HTTP/1.1 and in HTTP-NG.
version: 0.3-2 18/06/1999 author: Ronald Tschalär |
Method Summary | |
void | abort() Emergency stop. | synchronized int | available(ResponseHandler resph) Determines the number of available bytes. | synchronized void | close(IOException exception, boolean was_reset) Closes the socket and all associated streams. | synchronized void | close(ResponseHandler resph) Closes the associated stream. | synchronized void | closeSocketIfAllStreamsClosed() Close the socket if all the streams have been closed.
When a stream reaches eof it is removed from the response handler
list, but when somebody close()'s the response stream it is just
marked as such. | protected void | finalize() A safety net to close the connection. | synchronized Socket | getSocket() | RespInputStream | getStream(Response resp) creates an input stream for the response. | synchronized void | markForClose(Response resp) Mark this demux to not accept any more request and to close the
stream after this response or all requests have been
processed, or close immediately if no requests are registered. | int | read(byte[] b, int off, int len, ResponseHandler resph, int timeout) reads an array of bytes from the master stream. | void | register(Response resp_handler, Request req) Each Response must register with us. | void | restartTimer() Restarts the timer thread that will close an unused socket after
60 seconds. | synchronized long | skip(long num, ResponseHandler resph) skips a number of bytes in the master stream. | public String | toString() produces a string. |
StreamDemultiplexor | StreamDemultiplexor(int protocol, Socket sock, HTTPConnection connection) throws IOException(Code) | | a simple contructor.
Parameters: protocol - the protocol used on this stream. Parameters: sock - the socket which we're to demux. Parameters: connection - the http-connection this socket belongs to. |
abort | void abort()(Code) | | Emergency stop. Closes the socket and notifies the responses that
the requests are aborted.
since: V0.3 |
close | synchronized void close(IOException exception, boolean was_reset)(Code) | | Closes the socket and all associated streams. If exception
is not null then all active requests are retried.
There are five ways this method may be activated. 1) if an exception
occurs during read or write. 2) if the stream is marked for close but
no responses are outstanding (e.g. due to a timeout). 3) when the
markedForClose response is closed. 4) if all response streams up until
and including the markedForClose response have been closed. 5) if this
demux is finalized.
Parameters: exception - the IOException to be sent to the streams. Parameters: was_reset - if true then the exception is due to a connectionreset; otherwise it means we generated the exceptionourselves and this is a "normal" close. |
close | synchronized void close(ResponseHandler resph)(Code) | | Closes the associated stream. If this one has been markedForClose then
the socket is closed; else closeSocketIfAllStreamsClosed is invoked.
|
closeSocketIfAllStreamsClosed | synchronized void closeSocketIfAllStreamsClosed()(Code) | | Close the socket if all the streams have been closed.
When a stream reaches eof it is removed from the response handler
list, but when somebody close()'s the response stream it is just
marked as such. This means that all responses in the list have either
not been read at all or only partially read, but they might have been
close()'d meaning that nobody is interested in the data. So If all the
response streams up till and including the one markedForClose have
been close()'d then we can remove them from our list and close the
socket.
Note: if the response list is emtpy or if no response is
markedForClose then this method does nothing. Specifically it does
not close the socket. We only want to close the socket if we've been
told to do so.
Also note that there might still be responses in the list after
the markedForClose one. These are due to us having pipelined more
requests to the server than it's willing to serve on a single
connection. These requests will be retried if possible.
|
finalize | protected void finalize() throws Throwable(Code) | | A safety net to close the connection.
|
getSocket | synchronized Socket getSocket()(Code) | | returns the socket associated with this demux
|
getStream | RespInputStream getStream(Response resp)(Code) | | creates an input stream for the response.
Parameters: resp - the response structure requesting the stream an InputStream |
markForClose | synchronized void markForClose(Response resp)(Code) | | Mark this demux to not accept any more request and to close the
stream after this response or all requests have been
processed, or close immediately if no requests are registered.
Parameters: response - the Response after which the connection shouldbe closed. |
restartTimer | void restartTimer()(Code) | | Restarts the timer thread that will close an unused socket after
60 seconds.
|
skip | synchronized long skip(long num, ResponseHandler resph) throws IOException(Code) | | skips a number of bytes in the master stream. This is done via a
dummy read, as the socket input stream doesn't like skip()'s.
|
toString | public String toString()(Code) | | produces a string.
a string containing the class name and protocol number |
|
|