|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vodafone360.people.service.transport.tcp.ResponseReaderThread
public class ResponseReaderThread
Reads responses from a TCP sockets and adds them to the response decoder. Errors are called and passed back to the RpgTcpConnectionThread.
Field Summary | |
---|---|
private TcpConnectionThread |
mConnThread
The main connection thread to call back when an error occured. |
protected static ResponseReaderThread |
mCurrentThread
The ResponseReaderThread that was created by the TcpConnectionThread. |
private DecoderThread |
mDecoder
Decodes all responses coming in. |
protected java.io.DataInputStream |
mIs
The input stream to read responses from. |
protected boolean |
mIsConnectionRunning
Indicates that the thread is active and connected. |
private java.net.Socket |
mSocket
The socket to read from. |
protected java.lang.Thread |
mThread
Represents the thread that reads responses. |
private static long |
THREAD_SLEEP_TIME
Sleep time (in milliseconds) of the thread in between reads. |
Constructor Summary | |
---|---|
ResponseReaderThread(TcpConnectionThread connThread,
DecoderThread decoder,
java.net.Socket socket)
Constructs a new response reader used for reading bytes from a socket connection. |
Method Summary | |
---|---|
private void |
checkForDuplicateThreads()
Checks whether the current thread is not the same as the thread that should be running. |
private byte[] |
readNextResponse()
Attempts to read all the bytes from the DataInputStream and writes them to a byte array where they are processed for further use. |
void |
run()
Overrides the Thread.run() method and continuously calls the readResponses() method which blocks and reads responses or throws an exception that needs to be handled by reconnecting the sockets. |
void |
setInputStream(java.io.InputStream inputStream)
Sets the input stream that will be used to read responses from. |
void |
startConnection()
Starts the connection by setting the connection flag and spawning a new thread in which responses can be read without interfering with the rest of the client. |
void |
stopConnection()
Stops the connection by closing the input stream and setting it to null. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long THREAD_SLEEP_TIME
protected static ResponseReaderThread mCurrentThread
private DecoderThread mDecoder
private TcpConnectionThread mConnThread
protected java.io.DataInputStream mIs
protected boolean mIsConnectionRunning
protected java.lang.Thread mThread
private java.net.Socket mSocket
Constructor Detail |
---|
public ResponseReaderThread(TcpConnectionThread connThread, DecoderThread decoder, java.net.Socket socket)
connThread
- The connection thread that manages this and the
heartbeat sender thread. It is called back whenever an error
occured reading from the socket input stream.decoder
- Used to decode all incoming responses.Method Detail |
---|
public void startConnection()
public void stopConnection()
public void setInputStream(java.io.InputStream inputStream)
inputStream
- The input stream to read from. Should not be null as
this would trigger a reconnect of the whole socket and cause
all transport-threads to be restarted.public void run()
run
in interface java.lang.Runnable
private byte[] readNextResponse() throws java.io.IOException, java.io.EOFException
Attempts to read all the bytes from the DataInputStream and writes them to a byte array where they are processed for further use.
As this method uses InputStream.read() it blocks the execution until a byte has been read, the socket was closed (at which point an IOException will be thrown), or the end of the file has been reached (resulting in a EOFException being thrown).
java.io.IOException
- Thrown if something went wrong trying to read or
write a byte from or to a stream.
java.io.EOFException
- Thrown if the end of the stream has been reached
unexpectedly.private void checkForDuplicateThreads()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc