public class KeepAliveManager extends Object
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.
Modifier and Type | Method and Description |
---|---|
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.
|
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.
Copyright © 2003-2007 Jive Software.