|
|||||||||
| Home >> All >> [ HTTPClient overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
HTTPClient
Class StreamDemultiplexor

java.lang.ObjectHTTPClient.StreamDemultiplexor
- All Implemented Interfaces:
- GlobalConstants
- class StreamDemultiplexor
- extends java.lang.Object
- implements GlobalConstants
- extends java.lang.Object
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
| Field Summary | |
static int |
CD_0
|
static int |
CD_CHUNKED
|
static int |
CD_CLOSE
|
static int |
CD_CONTLEN
|
static int |
CD_HDRS
|
static int |
CD_MP_BR
|
static int |
CD_NONE
Content delimiters |
private int |
chunk_len
number of unread bytes in current chunk (if transf-enc == chunked) |
private HTTPConnection |
Connection
the connection we're working for |
private int |
cur_timeout
the currently set timeout for the socket |
static boolean |
DebugAll
Debug variables |
static boolean |
DebugAuth
|
static boolean |
DebugConn
|
static boolean |
DebugDemux
|
static boolean |
DebugMods
|
static boolean |
DebugResp
|
static boolean |
DebugSocks
|
static boolean |
DebugURLC
|
static int |
HTTP
possible http protocols we (might) handle |
static int |
HTTP_1_0
some known http versions |
static int |
HTTP_1_1
|
static int |
HTTP_NG
|
static int |
HTTPS
|
private ResponseHandler |
MarkedForClose
signals after the closing of which stream to close the socket |
private int |
Protocol
the protocol were handling request for |
private LinkedList |
RespHandlerList
a Vector to hold the list of response handlers were serving |
static int |
SHTTP
|
private java.net.Socket |
Sock
the socket this hangs off |
private ExtBufferedInputStream |
Stream
the input stream to demultiplex |
private SocketTimeout.TimeoutEntry |
Timer
timer used to close the socket if unused for a given time |
private static SocketTimeout |
TimerThread
timer thread which implements the timers |
| Constructor Summary | |
(package private) |
StreamDemultiplexor(int protocol,
java.net.Socket sock,
HTTPConnection connection)
a simple contructor. |
| Method Summary | |
(package private) void |
abort()
Emergency stop. |
(package private) int |
available(ResponseHandler resph)
Determines the number of available bytes. |
(package private) void |
close(java.io.IOException exception,
boolean was_reset)
Closes the socket and all associated streams. |
(package private) void |
close(ResponseHandler resph)
Closes the associated stream. |
(package private) void |
closeSocketIfAllStreamsClosed()
Close the socket if all the streams have been closed. |
protected void |
finalize()
A safety net to close the connection. |
(package private) java.net.Socket |
getSocket()
returns the socket associated with this demux |
(package private) RespInputStream |
getStream(Response resp)
creates an input stream for the response. |
private void |
init(java.net.Socket sock)
Initializes the demultiplexor with a new socket. |
(package private) 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. |
(package private) int |
read(byte[] b,
int off,
int len,
ResponseHandler resph,
int timeout)
reads an array of bytes from the master stream. |
(package private) void |
register(Response resp_handler,
Request req)
Each Response must register with us. |
(package private) void |
restartTimer()
Restarts the timer thread that will close an unused socket after 60 seconds. |
private void |
retry_requests(java.io.IOException exception,
boolean was_reset)
Retries outstanding requests. |
(package private) long |
skip(long num,
ResponseHandler resph)
skips a number of bytes in the master stream. |
java.lang.String |
toString()
produces a string. |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
Protocol
private int Protocol
- the protocol were handling request for
Connection
private HTTPConnection Connection
- the connection we're working for
Stream
private ExtBufferedInputStream Stream
- the input stream to demultiplex
Sock
private java.net.Socket Sock
- the socket this hangs off
MarkedForClose
private ResponseHandler MarkedForClose
- signals after the closing of which stream to close the socket
Timer
private SocketTimeout.TimeoutEntry Timer
- timer used to close the socket if unused for a given time
TimerThread
private static SocketTimeout TimerThread
- timer thread which implements the timers
RespHandlerList
private LinkedList RespHandlerList
- a Vector to hold the list of response handlers were serving
chunk_len
private int chunk_len
- number of unread bytes in current chunk (if transf-enc == chunked)
cur_timeout
private int cur_timeout
- the currently set timeout for the socket
DebugAll
public static final boolean DebugAll
- Debug variables
- See Also:
- Constant Field Values
DebugConn
public static final boolean DebugConn
- See Also:
- Constant Field Values
DebugResp
public static final boolean DebugResp
- See Also:
- Constant Field Values
DebugDemux
public static final boolean DebugDemux
- See Also:
- Constant Field Values
DebugAuth
public static final boolean DebugAuth
- See Also:
- Constant Field Values
DebugSocks
public static final boolean DebugSocks
- See Also:
- Constant Field Values
DebugMods
public static final boolean DebugMods
- See Also:
- Constant Field Values
DebugURLC
public static final boolean DebugURLC
- See Also:
- Constant Field Values
HTTP
public static final int HTTP
- possible http protocols we (might) handle
- See Also:
- Constant Field Values
HTTPS
public static final int HTTPS
- See Also:
- Constant Field Values
SHTTP
public static final int SHTTP
- See Also:
- Constant Field Values
HTTP_NG
public static final int HTTP_NG
- See Also:
- Constant Field Values
HTTP_1_0
public static final int HTTP_1_0
- some known http versions
- See Also:
- Constant Field Values
HTTP_1_1
public static final int HTTP_1_1
- See Also:
- Constant Field Values
CD_NONE
public static final int CD_NONE
- Content delimiters
- See Also:
- Constant Field Values
CD_HDRS
public static final int CD_HDRS
- See Also:
- Constant Field Values
CD_0
public static final int CD_0
- See Also:
- Constant Field Values
CD_CLOSE
public static final int CD_CLOSE
- See Also:
- Constant Field Values
CD_CONTLEN
public static final int CD_CONTLEN
- See Also:
- Constant Field Values
CD_CHUNKED
public static final int CD_CHUNKED
- See Also:
- Constant Field Values
CD_MP_BR
public static final int CD_MP_BR
- See Also:
- Constant Field Values
| Constructor Detail |
StreamDemultiplexor
StreamDemultiplexor(int protocol,
java.net.Socket sock,
HTTPConnection connection)
throws java.io.IOException
- a simple contructor.
| Method Detail |
init
private void init(java.net.Socket sock) throws java.io.IOException
- Initializes the demultiplexor with a new socket.
register
void register(Response resp_handler, Request req) throws RetryException
- Each Response must register with us.
getStream
RespInputStream getStream(Response resp)
- creates an input stream for the response.
restartTimer
void restartTimer()
- Restarts the timer thread that will close an unused socket after
60 seconds.
read
int read(byte[] b,
int off,
int len,
ResponseHandler resph,
int timeout)
throws java.io.IOException
- reads an array of bytes from the master stream.
skip
long skip(long num,
ResponseHandler resph)
throws java.io.IOException
- 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.
available
int available(ResponseHandler resph) throws java.io.IOException
- Determines the number of available bytes.
close
void close(java.io.IOException exception, boolean was_reset)
- 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.
retry_requests
private void retry_requests(java.io.IOException exception, boolean was_reset)
- Retries outstanding requests. Well, actually the RetryModule does
that. Here we just throw a RetryException for each request so that
the RetryModule can catch and handle them.
close
void close(ResponseHandler resph)
- Closes the associated stream. If this one has been markedForClose then
the socket is closed; else closeSocketIfAllStreamsClosed is invoked.
closeSocketIfAllStreamsClosed
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. 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.
getSocket
java.net.Socket getSocket()
- returns the socket associated with this demux
markForClose
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.
abort
void abort()
- Emergency stop. Closes the socket and notifies the responses that
the requests are aborted.
- Since:
- V0.3
finalize
protected void finalize()
throws java.lang.Throwable
- A safety net to close the connection.
toString
public java.lang.String toString()
- produces a string.
|
|||||||||
| Home >> All >> [ HTTPClient overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
HTTPClient.StreamDemultiplexor