|
Smack | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jivesoftware.smack.keepalive.KeepAliveManager
public class KeepAliveManager
Using an implementation of XMPP Ping (XEP-0199). This class provides keepalive functionality with the server that will periodically "ping" the server to maintain and/or verify that the connection still exists.
The ping is done at the application level and is therefore protocol agnostic. It will thus work for both standard TCP connections as well as BOSH or any other transport protocol. It will also work regardless of whether the server supports the Ping extension, since an error response to the ping serves the same purpose as a pong.
Method Summary | |
---|---|
void |
addPingFailedListener(PingFailedListener listener)
Add listener for notification when a server ping fails. |
static KeepAliveManager |
getInstanceFor(Connection connection)
Retrieves a KeepAliveManager for the specified Connection , creating one if it doesn't already
exist. |
long |
getPingInterval()
Gets the ping interval. |
long |
getTimeSinceLastContact()
Returns the elapsed time (in milliseconds) since the last successful contact with the server (i.e. |
void |
removePingFailedListener(PingFailedListener listener)
Remove the listener. |
void |
setPingInterval(long newPingInterval)
Sets the ping interval. |
void |
stopPinging()
Stops pinging the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static KeepAliveManager getInstanceFor(Connection connection)
KeepAliveManager
for the specified Connection
, creating one if it doesn't already
exist.
connection
- The connection the manager is attached to.
public void setPingInterval(long newPingInterval)
pingInterval
- The new ping time interval in milliseconds.public void stopPinging()
To restart, call setPingInterval(long)
.
public long getPingInterval()
public void addPingFailedListener(PingFailedListener listener)
Please note that this doesn't necessarily mean that the connection is lost, a slow to respond server could also cause a failure due to taking too long to respond and thus causing a reply timeout.
listener
- The listener to be calledpublic void removePingFailedListener(PingFailedListener listener)
listener
- The listener to be removed.public long getTimeSinceLastContact()
Note: Result is -1 if no message has been received since manager was created and 0 if the elapsed time is negative due to a clock reset.
|
Smack | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |