class TcpSocketReader
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
BEGIN_SUCCESSFUL_RESPONSE |
private static java.lang.String |
END_OF_RESPONSE |
private boolean |
keepAlive
True if this thread should continue, false if it should terminate
|
private java.util.Queue<Message> |
msgsWaitingForResponseQueue
Queue of messages which are waiting for their associated responses to be
received from the server
|
private java.io.BufferedReader |
socketBufferedReader
BufferedReader used to read from the socket
|
private TcpClient |
tcpClient
The TcpClient which instantiated this TcpSocketReader
|
private static java.lang.String |
UPDATE_AVAILABLE_STRING_PREFIX |
Constructor and Description |
---|
TcpSocketReader(java.net.Socket socket,
TcpClient tcpClient)
Constructs a TcpSocketReader
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
addToWaitingForResponseQueue(Message msgNeedingResponse)
Adds the message specified by the parameter to the queue of messages which
are waiting for a response.
|
private void |
addUpdateAvailableMsgToCompletedQueue(java.lang.String msg)
Handler for UPDATE_AVAILABLE being received.
|
(package private) Message |
getResponseFromSocket()
Each call to this function is intended to build a response for the oldest
message which hasn't been responded to.
|
private void |
logMsg(java.lang.String msg)
Logs/outputs a message.
|
(package private) Message |
pollMostRecentlyRespondedToMsgAndSetResponse(java.lang.String response,
Message.ResponseType responseMsgType)
Executes poll() on msgsWaitingForResponseQueue, which should always contain
at least one Message when this function is executed.
|
(package private) void |
requestStop()
Sets the keepAlive boolean to false, so that if this thread is interrupted or
the socket is closed, the thread will die.
|
void |
run()
The function called when a new TcpSocketReader thread is executed.
|
private static final java.lang.String BEGIN_SUCCESSFUL_RESPONSE
private static final java.lang.String END_OF_RESPONSE
private static final java.lang.String UPDATE_AVAILABLE_STRING_PREFIX
private final java.io.BufferedReader socketBufferedReader
private final java.util.Queue<Message> msgsWaitingForResponseQueue
private boolean keepAlive
private final TcpClient tcpClient
TcpSocketReader(java.net.Socket socket, TcpClient tcpClient) throws java.io.IOException
socket
- A socket which is connected to the servertcpClient
- The TcpClient which instantiated this TcpSocketReaderjava.io.IOException
- If an error occurs when attempting to call getInputStream() on
the socket paramvoid addToWaitingForResponseQueue(Message msgNeedingResponse)
msgNeedingResponse
- The message whose response is requestedMessage pollMostRecentlyRespondedToMsgAndSetResponse(java.lang.String response, Message.ResponseType responseMsgType)
response
- The responseMsg field's value to be setresponseMsgType
- The responseMsgType field's value to be setpublic void run()
run
in interface java.lang.Runnable
Message getResponseFromSocket() throws java.io.IOException
java.io.IOException
- When an error has occurred when reading the socket.java.lang.IllegalStateException
- If the new response specifier is sent before the response being
built is complete.private void addUpdateAvailableMsgToCompletedQueue(java.lang.String msg)
msg
- The UPDATE_AVAILABLE + timestamp string from rtlsdrdprivate void logMsg(java.lang.String msg)
msg
- The msg to logvoid requestStop()