|
|||||||||
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.PollThread
public class PollThread
Field Summary | |
---|---|
protected static byte |
ACTIVE_MODE
|
protected static int |
DEFAULT_BATCHSIZE
|
private static byte |
IDLE_MODE
|
private static int |
LONG_POLLING_INTERVAL
|
private int |
mBatchsize
|
private int |
mBlankHeaderCount
|
private DecoderThread |
mDecoder
|
private boolean |
mHasErrorOccured
|
private RpgHeader |
mHeader
|
private HttpClient |
mHttpClient
|
private boolean |
mIsConnectionRunning
|
private byte |
mMode
|
private java.lang.Object |
mPollLock
|
private int |
mRetryCount
|
private HttpConnectionThread |
mRpgRequesterThread
|
private java.lang.Object |
mRunLock
|
private java.net.URI |
mUrl
|
private static int |
NETWORK_NO_COVERAGE_RETRIES
|
private static long |
NETWORK_RETRY_INTERVAL
|
private static java.lang.String |
RPG_BATCH_SIZE_KEY
|
private static java.lang.String |
RPG_MODE_ACTIVE
|
private static java.lang.String |
RPG_MODE_KEY
|
private static java.lang.String |
RPG_POLLING_INTERVAL_KEY
|
protected static int |
SHORT_POLLING_INTERVAL
|
Constructor Summary | |
---|---|
protected |
PollThread(HttpConnectionThread connThread)
|
Method Summary | |
---|---|
private void |
consumeResponse(HttpResponse response)
|
boolean |
getHasCoverage()
Returns true if the device has coverage and the servers are not down. |
private void |
handleResponse(HttpResponse response)
Looks at the response and adds it to the necessary decoder. |
protected void |
invokePoll(int pollInterval,
int batchSize,
byte mode)
Invokes a poll on the RPG with the passed arguments. |
private HttpResponse |
postHTTPRequest(byte[] postData,
java.net.URI uri,
java.lang.String contentType)
Posts an HTTP request with data to a URL under a certain content type. |
private void |
retryConnection()
Retries to connect to the backend (if in active mode) every NETWORK_RETRY_INTERVAL seconds. |
void |
run()
Carries out an initial poll with a short interval to have the RPG set up the presence roosters then does poll after poll with the default polling interval to keep the connection alive. |
private byte[] |
serializeRPGPoll(int pollInterval,
int batchSize,
byte mode)
Serializes a poll to hessian and includes the RPG header. |
private void |
setHttpClient()
|
protected void |
startConnection(DecoderThread decoder)
Starts the connection. |
protected void |
startRpgPolling()
Starts the RPG polling in active mode. |
protected void |
stopConnection()
Attempts to stop the connection. |
private void |
stopRpgPolling()
We need to inform controller about the error here. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String RPG_MODE_KEY
private static final java.lang.String RPG_MODE_ACTIVE
private static final java.lang.String RPG_BATCH_SIZE_KEY
private static final java.lang.String RPG_POLLING_INTERVAL_KEY
protected static final byte ACTIVE_MODE
private static final byte IDLE_MODE
private static final int LONG_POLLING_INTERVAL
protected static final int SHORT_POLLING_INTERVAL
protected static final int DEFAULT_BATCHSIZE
private static final int NETWORK_NO_COVERAGE_RETRIES
private static final long NETWORK_RETRY_INTERVAL
private HttpConnectionThread mRpgRequesterThread
private DecoderThread mDecoder
private boolean mIsConnectionRunning
private boolean mHasErrorOccured
private int mBlankHeaderCount
private int mRetryCount
private byte mMode
private int mBatchsize
private java.net.URI mUrl
private HttpClient mHttpClient
private RpgHeader mHeader
private final java.lang.Object mPollLock
private final java.lang.Object mRunLock
Constructor Detail |
---|
protected PollThread(HttpConnectionThread connThread)
Method Detail |
---|
protected void startConnection(DecoderThread decoder)
private void setHttpClient()
protected void stopConnection()
public void run()
run
in interface java.lang.Runnable
protected void invokePoll(int pollInterval, int batchSize, byte mode) throws java.lang.Exception
pollInterval
- The polling interval the server takes as an argument.
LONG_POLLING_INTERVAL should be used for all normal polls,
SHORT_POLLING_INTERVAL for the initial poll.batchSize
- The maximum batch size of the client. DEFAULT_BATCHSIZE
should be used by default.mode
- The mode to use. ACTIVE_MODE and IDLE_MODE are available.
java.lang.Exception
private HttpResponse postHTTPRequest(byte[] postData, java.net.URI uri, java.lang.String contentType) throws java.lang.Exception
postData
- A byte array representing the data to be posted.uri
- The URI to post the data to.contentType
- The content type to post under.
java.lang.Exception
- Thrown if the request failed for HTTP_MAX_RETRY_COUNT
number of times.private void handleResponse(HttpResponse response) throws java.lang.Exception
Looks at the response and adds it to the necessary decoder.
TODO: this method should be worked on. The decoder should take care of deciding which methods are decoded in which way.
response
- The server response to decode.
java.lang.Exception
- Thrown if the returned status line was null or if the
response was null.private void consumeResponse(HttpResponse response)
private byte[] serializeRPGPoll(int pollInterval, int batchSize, byte mode) throws java.io.IOException
pollInterval
- The polling interval to use. LONG_POLLING_INTERVAL or
SHORT_POLLING_INTERVAL.batchSize
- The batch size to use on the RPG.mode
- The mode to use. Possible values: RPG_MODE_ACTIVE,
RPG_MODE_IDLE
java.io.IOException
private void stopRpgPolling()
protected void startRpgPolling() throws java.net.MalformedURLException, java.net.URISyntaxException
java.net.MalformedURLException
- Thrown if the URL is not in the correct
format.
java.net.URISyntaxException
- Thrown if the URL is not in the correct
format.private void retryConnection()
public boolean getHasCoverage()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc