Search in sources :

Example 1 with InternalProcessStanzaSmackFuture

use of org.jivesoftware.smack.SmackFuture.InternalProcessStanzaSmackFuture in project Smack by igniterealtime.

the class PingManager method pingAsync.

public SmackFuture<Boolean, Exception> pingAsync(final Jid jid, long pongTimeout) {
    final InternalProcessStanzaSmackFuture<Boolean, Exception> future = new InternalProcessStanzaSmackFuture<Boolean, Exception>() {

        @Override
        public void handleStanza(Stanza packet) {
            setResult(true);
        }

        @Override
        public boolean isNonFatalException(Exception exception) {
            if (exception instanceof XMPPErrorException) {
                XMPPErrorException xmppErrorException = (XMPPErrorException) exception;
                if (isValidErrorPong(jid, xmppErrorException)) {
                    setResult(true);
                    return true;
                }
            }
            return false;
        }
    };
    XMPPConnection connection = connection();
    Ping ping = new Ping(connection, jid);
    connection.sendIqRequestAsync(ping, pongTimeout).onSuccess(new SuccessCallback<IQ>() {

        @Override
        public void onSuccess(IQ result) {
            future.processStanza(result);
        }
    }).onError(new ExceptionCallback<Exception>() {

        @Override
        public void processException(Exception exception) {
            future.processException(exception);
        }
    });
    return future;
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) SuccessCallback(org.jivesoftware.smack.util.SuccessCallback) InternalProcessStanzaSmackFuture(org.jivesoftware.smack.SmackFuture.InternalProcessStanzaSmackFuture) Stanza(org.jivesoftware.smack.packet.Stanza) Ping(org.jivesoftware.smackx.ping.packet.Ping) IQ(org.jivesoftware.smack.packet.IQ) XMPPConnection(org.jivesoftware.smack.XMPPConnection) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException)

Aggregations

NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 InternalProcessStanzaSmackFuture (org.jivesoftware.smack.SmackFuture.InternalProcessStanzaSmackFuture)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 IQ (org.jivesoftware.smack.packet.IQ)1 Stanza (org.jivesoftware.smack.packet.Stanza)1 SuccessCallback (org.jivesoftware.smack.util.SuccessCallback)1 Ping (org.jivesoftware.smackx.ping.packet.Ping)1