|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.vodafone360.people.service.transport.http.HttpConnectionThread
public class HttpConnectionThread
HTTP connection thread handles issuing of RPG requests over HTTP to server.
Field Summary | |
---|---|
private DecoderThread |
mDecoder
|
private HttpClient |
mHttpClient
|
private boolean |
mIsConnectionRunning
|
private boolean |
mIsFirstTimePoll
|
private boolean |
mIsPolling
|
private PollThread |
mPollThread
|
private int |
mRetryCount
|
private java.net.URI |
mRpgUrl
|
private java.lang.Object |
mRunLock
|
private java.lang.Object |
mSendLock
|
private java.lang.Thread |
mThread
|
Constructor Summary | |
---|---|
HttpConnectionThread(DecoderThread decoder)
|
Method Summary | |
---|---|
void |
addErrorToResponseQueue(java.util.List<java.lang.Integer> reqIds)
Adds errors to the response queue whenever there is an HTTP error on the backend. |
private void |
addToDecoder(byte[] input,
java.util.List<java.lang.Integer> reqIds)
Adds a response to the response decoder. |
private void |
finishResponse(HttpResponse response)
Finishes reading the response in order to unblock the current connection. |
boolean |
getIsConnected()
Returns true if the current connection thread is connected. |
boolean |
getIsRpgConnectionActive()
Returns true if we have an open RPG connection or false if we do not have one. |
void |
handleApiResponse(HttpResponse response,
java.util.List<java.lang.Integer> reqIds)
Handles the synchronous responses for the authentication calls which go against the API directly by adding it to the queue and checking if the response code was a HTTP 200. |
private boolean |
handleRpgResponse(HttpResponse response,
java.util.List<java.lang.Integer> reqIds)
Checks if the response to an RPG request was fired off correctly. |
static void |
logD(java.lang.String tag,
java.lang.String message)
|
static void |
logE(java.lang.String tag,
java.lang.String message,
java.lang.Throwable error)
|
static void |
logI(java.lang.String tag,
java.lang.String message)
|
static void |
logV(java.lang.String tag,
java.lang.String message)
|
static void |
logW(java.lang.String tag,
java.lang.String message)
|
void |
notifyOfItemInRequestQueue()
Kicks the request queue as soon as there are more requests on the queue. |
void |
notifyOfRegainedNetworkCoverage()
Called whenever the device regains network coverage. |
void |
notifyOfUiActivity()
If the UI is currently being used by the user this method gets called. |
void |
onLoginStateChanged(boolean isLoggedIn)
Triggered by the ConnectionManager whenever the login engine has detected a change in the currently held session. |
HttpResponse |
postHTTPRequest(byte[] postData,
java.net.URI uri,
java.lang.String contentType)
Posts the serialized data to the RPG and synchronously grabs the response. |
private byte[] |
prepareRPGRequests(java.util.List<Request> requests,
java.util.List<java.lang.Integer> reqIds)
Takes all requests objects and writes its serialized data to a byte array for further posting to the RPG. |
void |
run()
Sends out synchronous requests (for authentication) to the API and asynchronous calls to the RPG as soon as there are requests on the request queue. |
void |
setHttpClient()
Sets HTTP settings. |
private void |
startPollThread()
This method is called when log-in is detected. |
void |
startThread()
Starts the RPG connection as a thread and also launches the polling thread. |
private void |
stopPollThread()
Stops the polling thread. |
void |
stopThread()
Stops the current thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.lang.Thread mThread
private volatile boolean mIsConnectionRunning
private PollThread mPollThread
private DecoderThread mDecoder
private HttpClient mHttpClient
private int mRetryCount
private java.net.URI mRpgUrl
private boolean mIsPolling
private boolean mIsFirstTimePoll
private final java.lang.Object mSendLock
private final java.lang.Object mRunLock
Constructor Detail |
---|
public HttpConnectionThread(DecoderThread decoder)
Method Detail |
---|
public void startThread()
startThread
in interface IConnection
public void setHttpClient()
public void stopThread()
stopThread
in interface IConnection
public void run()
Sends out synchronous requests (for authentication) to the API and asynchronous calls to the RPG as soon as there are requests on the request queue.
If there are no requests the thread is set to wait().
run
in interface java.lang.Runnable
private byte[] prepareRPGRequests(java.util.List<Request> requests, java.util.List<java.lang.Integer> reqIds)
requests
- A list of requests to serialize.reqIds
-
public HttpResponse postHTTPRequest(byte[] postData, java.net.URI uri, java.lang.String contentType) throws java.lang.Exception
postData
- The post data to send to the RPG.uri
- The URL to send the request to.contentType
- The content type to send as, usually
"application/binary)
An
- exception if the request went wrong after HTTP_MAX_RETRY_COUNT
retries.
java.lang.Exception
private boolean handleRpgResponse(HttpResponse response, java.util.List<java.lang.Integer> reqIds) throws java.lang.Exception
response
- The response to check for.reqIds
- The request IDs for the response.
java.lang.Exception
- Thrown if the response was null or the status line could
not be fetched.private void finishResponse(HttpResponse response)
response
- The response to finish reading on.public void handleApiResponse(HttpResponse response, java.util.List<java.lang.Integer> reqIds) throws java.lang.Exception
response
- The response to add to the decoder.reqIds
- The request IDs the response is to be decoded for.
java.lang.Exception
- Thrown if the status line could not be read or the
response is null.private void addToDecoder(byte[] input, java.util.List<java.lang.Integer> reqIds)
input
- The data of the response.reqIds
- The request IDs that a response was received for.public void addErrorToResponseQueue(java.util.List<java.lang.Integer> reqIds)
reqIds
- The request IDs the error happened for.public void notifyOfItemInRequestQueue()
notifyOfItemInRequestQueue
in interface IQueueListener
public void notifyOfRegainedNetworkCoverage()
notifyOfRegainedNetworkCoverage
in interface IConnection
private void startPollThread()
private void stopPollThread()
public void onLoginStateChanged(boolean isLoggedIn)
IConnection
onLoginStateChanged
in interface IConnection
isLoggedIn
- True if the user was just logged in, false if he was
logged out.public boolean getIsConnected()
IConnection
getIsConnected
in interface IConnection
public static void logE(java.lang.String tag, java.lang.String message, java.lang.Throwable error)
public static void logW(java.lang.String tag, java.lang.String message)
public static void logI(java.lang.String tag, java.lang.String message)
public static void logD(java.lang.String tag, java.lang.String message)
public static void logV(java.lang.String tag, java.lang.String message)
public boolean getIsRpgConnectionActive()
IConnection
getIsRpgConnectionActive
in interface IConnection
public void notifyOfUiActivity()
IConnection
notifyOfUiActivity
in interface IConnection
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc