public final class PingManager extends Manager
The default server ping interval is 30 minutes and can be modified with
setDefaultPingInterval(int) and setPingInterval(int).
| Modifier and Type | Method and Description |
|---|---|
static PingManager |
getInstanceFor(XMPPConnection connection)
Retrieves a
PingManager for the specified XMPPConnection, creating one if it doesn't already
exist. |
int |
getPingInterval()
Get the current ping interval.
|
boolean |
isPingSupported(org.jxmpp.jid.Jid jid)
Query the specified entity to see if it supports the Ping protocol (XEP-0199).
|
boolean |
ping(org.jxmpp.jid.Jid jid)
Same as calling
ping(Jid, long) with the defaultpacket reply
timeout. |
boolean |
ping(org.jxmpp.jid.Jid jid,
long pingTimeout)
Pings the given jid.
|
SmackFuture<java.lang.Boolean> |
pingAsync(org.jxmpp.jid.Jid jid) |
SmackFuture<java.lang.Boolean> |
pingAsync(org.jxmpp.jid.Jid jid,
long pongTimeout) |
boolean |
pingMyServer()
Pings the server.
|
boolean |
pingMyServer(boolean notifyListeners)
Pings the server.
|
boolean |
pingMyServer(boolean notifyListeners,
long pingTimeout)
Pings the server.
|
void |
pingServerIfNecessary()
Ping the server if deemed necessary because automatic server pings are
enabled (
setPingInterval(int)) and the ping interval has expired. |
void |
registerPingFailedListener(PingFailedListener listener)
Register a new PingFailedListener.
|
static void |
setDefaultPingInterval(int interval)
Set the default ping interval which will be used for new connections.
|
void |
setPingInterval(int pingInterval)
Set the interval in seconds between a automated server ping is send.
|
void |
unregisterPingFailedListener(PingFailedListener listener)
Unregister a PingFailedListener.
|
connection, getAuthenticatedConnectionOrThrow, schedulepublic static PingManager getInstanceFor(XMPPConnection connection)
PingManager for the specified XMPPConnection, creating one if it doesn't already
exist.connection - The connection the manager is attached to.public static void setDefaultPingInterval(int interval)
interval - the interval in secondspublic SmackFuture<java.lang.Boolean> pingAsync(org.jxmpp.jid.Jid jid)
public SmackFuture<java.lang.Boolean> pingAsync(org.jxmpp.jid.Jid jid, long pongTimeout)
public boolean ping(org.jxmpp.jid.Jid jid, long pingTimeout) throws SmackException.NotConnectedException, SmackException.NoResponseException, java.lang.InterruptedException
Use isPingSupported(Jid) to determine if XMPP Ping is supported
by the entity.
jid - The id of the entity the ping is being sent topingTimeout - The time to wait for a reply in millisecondsSmackException.NoResponseException - if there was no response from the jid.SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic boolean ping(org.jxmpp.jid.Jid jid) throws SmackException.NotConnectedException, SmackException.NoResponseException, java.lang.InterruptedException
ping(Jid, long) with the defaultpacket reply
timeout.jid - The id of the entity the ping is being sent toSmackException.NotConnectedExceptionSmackException.NoResponseException - if there was no response from the jid.java.lang.InterruptedExceptionpublic boolean isPingSupported(org.jxmpp.jid.Jid jid) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, java.lang.InterruptedException
jid - The id of the entity the query is being sent toXMPPException.XMPPErrorException - An XMPP related error occurred during the requestSmackException.NoResponseException - if there was no response from the jid.SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic boolean pingMyServer() throws SmackException.NotConnectedException, java.lang.InterruptedException
ping with the XMPP domain.
Unlike the ping(Jid) case, this method will return true even if
isPingSupported(Jid) is false.
SmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic boolean pingMyServer(boolean notifyListeners) throws SmackException.NotConnectedException, java.lang.InterruptedException
ping with the XMPP domain.
Unlike the ping(Jid) case, this method will return true even if
isPingSupported(Jid) is false.
notifyListeners - Notify the PingFailedListener in case of error if trueSmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic boolean pingMyServer(boolean notifyListeners, long pingTimeout) throws SmackException.NotConnectedException, java.lang.InterruptedException
ping with the XMPP domain.
Unlike the ping(Jid) case, this method will return true even if
isPingSupported(Jid) is false.
notifyListeners - Notify the PingFailedListener in case of error if truepingTimeout - The time to wait for a reply in millisecondsSmackException.NotConnectedExceptionjava.lang.InterruptedExceptionpublic void setPingInterval(int pingInterval)
pingInterval is positive, a new one will be scheduled in pingInterval seconds.
If the ping fails after 3 attempts waiting the connections reply timeout for an answer, then the ping failed listeners will be invoked.
pingInterval - the interval in seconds between the automated server pingspublic int getPingInterval()
public void registerPingFailedListener(PingFailedListener listener)
listener - the listener to invokepublic void unregisterPingFailedListener(PingFailedListener listener)
listener - the listener to removepublic void pingServerIfNecessary()
setPingInterval(int)) and the ping interval has expired.