|
|||||||||
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.HeartbeatSenderThread
public class HeartbeatSenderThread
Sends heartbeats to the RPG in order to keep the connection alive.
Field Summary | |
---|---|
private TcpConnectionThread |
mConnThread
The managing thread that needs to be called back if an IOException occurs sending a heartbeat. |
protected static HeartbeatSenderThread |
mCurrentThread
The HeartbeatSenderThread that was created by the TcpConnectionThread. |
protected long |
mHeartbeatInterval
This is the interval at which the heartbeat gets sent. |
private static long |
MILLIS_PER_SEC
The milliseconds in a second. |
private boolean |
mIsConnectionRunning
Indicates that the connection is running if true. |
protected java.io.OutputStream |
mOs
The output stream to write the heartbeat to. |
private RemoteService |
mService
The service under which context the hb sender runs in. |
private java.net.Socket |
mSocket
The socket to write to. |
protected java.lang.Thread |
mThread
The thread continuously sending the heartbeats. |
private PowerManager.WakeLock |
mWakeLock
Keeps a partial wake lock on the CPU that will prevent it from sleeping and allow the Sender to send off heartbeats. |
Fields inherited from interface com.vodafone360.people.service.transport.IWakeupListener |
---|
ALARM_HB_THREAD |
Constructor Summary | |
---|---|
HeartbeatSenderThread(TcpConnectionThread connThread,
RemoteService service,
java.net.Socket socket)
Constructs a heartbeat-sender and passes the connection thread to call back to in case of errors. |
Method Summary | |
---|---|
private byte[] |
getHeartbeatHessianPayload()
Returns a byte-array containing the data needed for sending a heartbeat to the RPG. |
boolean |
getIsActive()
Returns true if the heartbeat thread is currently running/active. |
void |
notifyOfWakeupAlarm()
Called whenever the Service receives a Wakeup Alarm intent. |
void |
run()
The run-method overriding Thread.run(). |
void |
sendHeartbeat()
Prepares the necessary Hessian payload and writes it directly to the open output-stream of the socket. |
void |
setOutputStream(java.io.OutputStream outputStream)
Sets the output-stream so that the heartbeat-sender can send its heartbeats to the RPG. |
void |
startConnection()
Sets the state of the connection to run and spawns a thread to run it in. |
void |
stopConnection()
Stops the heartbeat-senders connection and closes the output-stream to the socket-connection. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static HeartbeatSenderThread mCurrentThread
private static final long MILLIS_PER_SEC
private RemoteService mService
private TcpConnectionThread mConnThread
protected java.lang.Thread mThread
protected java.io.OutputStream mOs
protected long mHeartbeatInterval
private boolean mIsConnectionRunning
private PowerManager.WakeLock mWakeLock
private java.net.Socket mSocket
Constructor Detail |
---|
public HeartbeatSenderThread(TcpConnectionThread connThread, RemoteService service, java.net.Socket socket)
connThread
- The connection thread to call back to in case of
networking issues.service
- The remote service that we register with once we have set
the heartbeat alarm.Method Detail |
---|
public void startConnection()
public void stopConnection()
public void setOutputStream(java.io.OutputStream outputStream)
outputStream
- The open output-stream that the heartbeats shall be
sent to. Avoid passing null as this will result in an
error-callback to RpgTcpConnectionThread which will completely
reestablish the socket connection.public void run()
run
in interface java.lang.Runnable
public void sendHeartbeat() throws java.io.IOException, java.lang.Exception
java.lang.Exception
- Thrown if there was an unknown problem writing to the
output-stream.
java.io.IOException
- Thrown if there was a problem regarding IO while
writing to the output-stream.private byte[] getHeartbeatHessianPayload() throws java.io.IOException
java.io.IOException
- If there was an exception serializing the hash map to
a hessian byte array.public boolean getIsActive()
Returns true if the heartbeat thread is currently running/active.
Calling startConnection() will make this method return as the heartbeat thread gets started.
stopConnection() will stop the connection again and make this method return false.
public void notifyOfWakeupAlarm()
IWakeupListener
notifyOfWakeupAlarm
in interface IWakeupListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
JavaDoc