Search in sources :

Example 1 with SuccessCallback

use of org.jivesoftware.smack.util.SuccessCallback in project Smack by igniterealtime.

the class CarbonManager method sendUseCarbons.

private void sendUseCarbons(final boolean use, ExceptionCallback<Exception> exceptionCallback) {
    enabledByDefault = use;
    IQ setIQ = carbonsEnabledIQ(use);
    SmackFuture<IQ, Exception> future = connection().sendIqRequestAsync(setIQ);
    future.onSuccess(new SuccessCallback<IQ>() {

        @Override
        public void onSuccess(IQ result) {
            enabled_state = use;
        }
    }).onError(exceptionCallback);
}
Also used : SuccessCallback(org.jivesoftware.smack.util.SuccessCallback) IQ(org.jivesoftware.smack.packet.IQ) SmackException(org.jivesoftware.smack.SmackException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 2 with SuccessCallback

use of org.jivesoftware.smack.util.SuccessCallback 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)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 IQ (org.jivesoftware.smack.packet.IQ)2 SuccessCallback (org.jivesoftware.smack.util.SuccessCallback)2 SmackException (org.jivesoftware.smack.SmackException)1 InternalProcessStanzaSmackFuture (org.jivesoftware.smack.SmackFuture.InternalProcessStanzaSmackFuture)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Stanza (org.jivesoftware.smack.packet.Stanza)1 Ping (org.jivesoftware.smackx.ping.packet.Ping)1