|
|||||||||
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.TcpConnectionThread
public class TcpConnectionThread
Field Summary | |
---|---|
private static int |
BYTE_ARRAY_OUTPUT_STREAM_SIZE
|
private static int |
CONNECTION_RESTART_INTERVAL
If we have a connection error we try to restart after 60 seconds earliest |
private static int |
ERROR_RETRY_INTERVAL
|
private static int |
MAX_NUMBER_RETRIES
The maximum number of retries to reestablish a connection until we sleep until the user uses the UI or Settings.TCP_RETRY_BROKEN_CONNECTION_INTERVAL calls another retry. |
private java.io.ByteArrayOutputStream |
mBaos
|
private boolean |
mConnectionShouldBeRunning
|
private DecoderThread |
mDecoder
|
private boolean |
mDidCriticalErrorOccur
|
private HeartbeatSenderThread |
mHeartbeatSender
|
private java.io.InputStream |
mIs
|
private long |
mLastErrorRetryTime
|
private long |
mLastErrorTimestamp
|
private java.io.OutputStream |
mOs
|
private ResponseReaderThread |
mResponseReader
|
private int |
mRpgTcpPort
|
private java.lang.String |
mRpgTcpUrl
|
private RemoteService |
mService
|
private java.net.Socket |
mSocket
|
private java.lang.Thread |
mThread
|
private static int |
RPG_DEFAULT_TCP_PORT
|
private static java.lang.String |
RPG_FALLBACK_TCP_URL
|
private static int |
TCP_DEFAULT_TIMEOUT
|
Constructor Summary | |
---|---|
TcpConnectionThread(DecoderThread decoder,
RemoteService service)
|
Method Summary | |
---|---|
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. |
private void |
haltAndRetryConnection(int numberOfRetries)
Retries to establish a network connection after a network error has occurred or the coverage of the network was lost. |
private void |
invalidateRequests()
Invalidates all the requests so that the engines can either resend or post an error message for the user. |
void |
notifyOfItemInRequestQueue()
Notifies the implementation that a new request is available in the queue and should trigger its delivery to the backend. |
protected void |
notifyOfNetworkProblems()
Called back by the response reader, which should notice network problems first |
void |
notifyOfRegainedNetworkCoverage()
Called whenever the network coverage has been reestablished... |
void |
notifyOfUiActivity()
Gets notified whenever the user is using the UI. |
void |
onLoginStateChanged(boolean isLoggedIn)
Triggered by the ConnectionManager whenever the login engine has detected a change in the currently held session. |
private void |
reconnectSocket()
Attempts to reconnect the socket if it has been closed for some reason. |
void |
run()
|
private void |
startHelperThreads()
Starts the helper threads in order to be able to read responses and send heartbeats and passes them the needed input and output streams. |
void |
startThread()
Starts the main connection thread. |
private void |
stopConnection()
Stops the connection and its underlying socket implementation. |
private void |
stopHelperThreads()
Stops the helper threads and closes the input and output streams. |
void |
stopThread()
Stops the current connection thread. this should also stop any running sub-connection threads such as heartbeats or polls. |
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_FALLBACK_TCP_URL
private static final int RPG_DEFAULT_TCP_PORT
private static final int TCP_DEFAULT_TIMEOUT
private static final int ERROR_RETRY_INTERVAL
private static final int CONNECTION_RESTART_INTERVAL
private static final int MAX_NUMBER_RETRIES
private static final int BYTE_ARRAY_OUTPUT_STREAM_SIZE
private java.lang.Thread mThread
private RemoteService mService
private DecoderThread mDecoder
private boolean mConnectionShouldBeRunning
private boolean mDidCriticalErrorOccur
private java.io.InputStream mIs
private java.io.OutputStream mOs
private java.lang.String mRpgTcpUrl
private int mRpgTcpPort
private java.net.Socket mSocket
private HeartbeatSenderThread mHeartbeatSender
private ResponseReaderThread mResponseReader
private long mLastErrorRetryTime
private long mLastErrorTimestamp
private java.io.ByteArrayOutputStream mBaos
Constructor Detail |
---|
public TcpConnectionThread(DecoderThread decoder, RemoteService service)
Method Detail |
---|
public void run()
run
in interface java.lang.Runnable
public void notifyOfUiActivity()
notifyOfUiActivity
in interface IConnection
public void notifyOfRegainedNetworkCoverage()
IConnection
notifyOfRegainedNetworkCoverage
in interface IConnection
protected void notifyOfNetworkProblems()
private void reconnectSocket() throws java.io.IOException
java.io.IOException
- Thrown if something goes wrong while reconnecting the
socket.private void haltAndRetryConnection(int numberOfRetries)
Retries to establish a network connection after a network error has occurred or the coverage of the network was lost. The amount of retries depends on MAX_NUMBER_RETRIES.
A new retry is carried out each time an exception is thrown until the limit of retries has been reached.
numberOfRetries
- The amount of retries carried out until the
connection is given up.private void invalidateRequests()
public void startThread()
IConnection
startThread
in interface IConnection
public void stopThread()
IConnection
stopThread
in interface IConnection
private void startHelperThreads()
private void stopHelperThreads()
private void stopConnection()
public void notifyOfItemInRequestQueue()
IQueueListener
notifyOfItemInRequestQueue
in interface IQueueListener
public boolean getIsConnected()
IConnection
getIsConnected
in interface IConnection
public boolean getIsRpgConnectionActive()
IConnection
getIsRpgConnectionActive
in interface IConnection
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc