Class PingManager


  • public final class PingManager
    extends Manager
    Implements the XMPP Ping as defined by XEP-0199. The XMPP Ping protocol allows one entity to ping any other entity by simply sending a ping to the appropriate JID. PingManger also periodically sends XMPP pings to the server to avoid NAT timeouts and to test the connection status.

    The default server ping interval is 30 minutes and can be modified with setDefaultPingInterval(int) and setPingInterval(int).

    See Also:
    XEP-0199:XMPP Ping
    • Method Detail

      • setDefaultPingInterval

        public static void setDefaultPingInterval​(int interval)
        Set the default ping interval which will be used for new connections.
        Parameters:
        interval - the interval in seconds
      • pingAsync

        public SmackFuture<java.lang.Boolean,​java.lang.Exception> pingAsync​(Jid jid,
                                                                                  long pongTimeout)
      • ping

        public boolean ping​(Jid jid,
                            long pingTimeout)
                     throws SmackException.NotConnectedException,
                            SmackException.NoResponseException,
                            java.lang.InterruptedException
        Pings the given jid. This method will return false if an error occurs. The exception to this, is a server ping, which will always return true if the server is reachable, event if there is an error on the ping itself (i.e. ping not supported).

        Use isPingSupported(Jid) to determine if XMPP Ping is supported by the entity.

        Parameters:
        jid - The id of the entity the ping is being sent to
        pingTimeout - The time to wait for a reply in milliseconds
        Returns:
        true if a reply was received from the entity, false otherwise.
        Throws:
        SmackException.NoResponseException - if there was no response from the jid.
        SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • pingMyServer

        public boolean pingMyServer()
                             throws SmackException.NotConnectedException,
                                    java.lang.InterruptedException
        Pings the server. This method will return true if the server is reachable. It is the equivalent of calling ping with the XMPP domain.

        Unlike the ping(Jid) case, this method will return true even if isPingSupported(Jid) is false.

        Returns:
        true if a reply was received from the server, false otherwise.
        Throws:
        SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • pingMyServer

        public boolean pingMyServer​(boolean notifyListeners)
                             throws SmackException.NotConnectedException,
                                    java.lang.InterruptedException
        Pings the server. This method will return true if the server is reachable. It is the equivalent of calling ping with the XMPP domain.

        Unlike the ping(Jid) case, this method will return true even if isPingSupported(Jid) is false.

        Parameters:
        notifyListeners - Notify the PingFailedListener in case of error if true
        Returns:
        true if the user's server could be pinged.
        Throws:
        SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • pingMyServer

        public boolean pingMyServer​(boolean notifyListeners,
                                    long pingTimeout)
                             throws SmackException.NotConnectedException,
                                    java.lang.InterruptedException
        Pings the server. This method will return true if the server is reachable. It is the equivalent of calling ping with the XMPP domain.

        Unlike the ping(Jid) case, this method will return true even if isPingSupported(Jid) is false.

        Parameters:
        notifyListeners - Notify the PingFailedListener in case of error if true
        pingTimeout - The time to wait for a reply in milliseconds
        Returns:
        true if the user's server could be pinged.
        Throws:
        SmackException.NotConnectedException - if the XMPP connection is not connected.
        java.lang.InterruptedException - if the calling thread was interrupted.
      • setPingInterval

        public void setPingInterval​(int pingInterval)
        Set the interval in seconds between a automated server ping is send. A negative value disables automatic server pings. All settings take effect immediately. If there is an active scheduled server ping it will be canceled and, if 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.

        Parameters:
        pingInterval - the interval in seconds between the automated server pings
      • getPingInterval

        public int getPingInterval()
        Get the current ping interval.
        Returns:
        the interval between pings in seconds