1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-22 12:37:58 +01:00

Deprecate old async API

This commit is contained in:
Florian Schmaus 2017-08-16 13:46:42 +02:00
parent 798d158d32
commit 6203d163c4
5 changed files with 64 additions and 38 deletions

View file

@ -1476,12 +1476,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
streamFeatures.put(key, feature);
}
@SuppressWarnings("deprecation")
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
StanzaListener callback) throws NotConnectedException, InterruptedException {
sendStanzaWithResponseCallback(stanza, replyFilter, callback, null);
}
@SuppressWarnings("deprecation")
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
StanzaListener callback, ExceptionCallback exceptionCallback)
@ -1571,7 +1573,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
return future;
}
@SuppressWarnings("FutureReturnValueIgnored")
@SuppressWarnings({ "FutureReturnValueIgnored", "deprecation" })
@Override
public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter replyFilter,
final StanzaListener callback, final ExceptionCallback exceptionCallback,
@ -1624,18 +1626,21 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
sendStanza(stanza);
}
@SuppressWarnings("deprecation")
@Override
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback)
throws NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iqRequest, callback, null);
}
@SuppressWarnings("deprecation")
@Override
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException {
sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getReplyTimeout());
}
@SuppressWarnings("deprecation")
@Override
public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback,
final ExceptionCallback exceptionCallback, long timeout)

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014 Florian Schmaus
* Copyright © 2014-2017 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,12 @@
*/
package org.jivesoftware.smack;
/**
* This interface has been deprecated. Please use org.jivesoftware.smack.util.ExceptionCallback instead.
*
* @deprecated use {@link org.jivesoftware.smack.util.ExceptionCallback} instead.
*/
@Deprecated
public interface ExceptionCallback {
public void processException(Exception exception);

View file

@ -428,7 +428,6 @@ public interface XMPPConnection {
*/
public boolean hasFeature(String element, String namespace);
/**
* Send an IQ request asynchronously. The connection's default reply timeout will be used.
*
@ -447,7 +446,8 @@ public interface XMPPConnection {
public SmackFuture<IQ, Exception> sendIqRequestAsync(IQ request, long timeout);
/**
* Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter. The connection's default reply timeout will be used.
* Send a stanza asynchronously, waiting for exactly one response stanza using the given reply filter. The
* connection's default reply timeout will be used.
*
* @param stanza the stanza to send.
* @param replyFilter the filter used for the response stanza.
@ -477,9 +477,11 @@ public interface XMPPConnection {
* @param replyFilter the filter used to determine response stanza (required)
* @param callback the callback invoked if there is a response (required)
* @throws NotConnectedException
* @throws InterruptedException
* @throws InterruptedException
* @deprecated use {@link #sendAsync(Stanza, StanzaFilter)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
StanzaListener callback) throws NotConnectedException, InterruptedException;
@ -497,10 +499,12 @@ public interface XMPPConnection {
* @param exceptionCallback the callback invoked if there is an exception (optional)
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendAsync(Stanza, StanzaFilter)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API. And do not forget to mark smack.ExceptionCallback deprecated too.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
@SuppressWarnings("deprecation") ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
/**
* Send a stanza and wait asynchronously for a response by using <code>replyFilter</code>.
@ -517,10 +521,12 @@ public interface XMPPConnection {
* @param timeout the timeout in milliseconds to wait for a response
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendAsync(Stanza, StanzaFilter, long)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
final StanzaListener callback, final ExceptionCallback exceptionCallback,
final StanzaListener callback, @SuppressWarnings("deprecation") final ExceptionCallback exceptionCallback,
long timeout) throws NotConnectedException, InterruptedException;
/**
@ -532,8 +538,10 @@ public interface XMPPConnection {
* @param callback the callback invoked if there is result response (required)
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendIqRequestAsync(IQ)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback) throws NotConnectedException, InterruptedException;
/**
@ -549,10 +557,12 @@ public interface XMPPConnection {
* @param exceptionCallback the callback invoked if there is an Exception optional
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendIqRequestAsync(IQ)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
@SuppressWarnings("deprecation") ExceptionCallback exceptionCallback) throws NotConnectedException, InterruptedException;
/**
* Send a IQ stanza and invoke <code>callback</code> if there is a result of
@ -568,10 +578,12 @@ public interface XMPPConnection {
* @param timeout the timeout in milliseconds to wait for a response
* @throws NotConnectedException
* @throws InterruptedException
* @deprecated use {@link #sendIqRequestAsync(IQ, long)} instead.
*/
// TODO: Mark deprecated in favor of the new SmackFuture based async API.
@Deprecated
// TODO: Remove in Smack 4.4.
public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback,
final ExceptionCallback exceptionCallback, long timeout)
@SuppressWarnings("deprecation") final ExceptionCallback exceptionCallback, long timeout)
throws NotConnectedException, InterruptedException;
/**

View file

@ -23,11 +23,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ExceptionCallback;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackFuture;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
@ -42,6 +42,8 @@ import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.ExceptionCallback;
import org.jivesoftware.smack.util.SuccessCallback;
import org.jivesoftware.smackx.carbons.packet.Carbon;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
@ -245,10 +247,9 @@ public final class CarbonManager extends Manager {
* </p>
*
* @param exceptionCallback the optional exception callback.
* @throws InterruptedException if the thread got interrupted while this action is performed.
* @since 4.2
*/
public void enableCarbonsAsync(ExceptionCallback exceptionCallback) throws InterruptedException {
public void enableCarbonsAsync(ExceptionCallback<Exception> exceptionCallback) {
sendUseCarbons(true, exceptionCallback);
}
@ -262,29 +263,24 @@ public final class CarbonManager extends Manager {
* </p>
*
* @param exceptionCallback the optional exception callback.
* @throws InterruptedException if the thread got interrupted while this action is performed.
* @since 4.2
*/
public void disableCarbonsAsync(ExceptionCallback exceptionCallback) throws InterruptedException {
public void disableCarbonsAsync(ExceptionCallback<Exception> exceptionCallback) {
sendUseCarbons(false, exceptionCallback);
}
private void sendUseCarbons(final boolean use, ExceptionCallback exceptionCallback) throws InterruptedException {
private void sendUseCarbons(final boolean use, ExceptionCallback<Exception> exceptionCallback) {
IQ setIQ = carbonsEnabledIQ(use);
try {
connection().sendIqWithResponseCallback(setIQ, new StanzaListener() {
@Override
public void processStanza(Stanza packet) {
enabled_state = use;
}
}, exceptionCallback);
}
catch (NotConnectedException e) {
if (exceptionCallback != null) {
exceptionCallback.processException(e);
SmackFuture<IQ, Exception> future = connection().sendIqRequestAsync(setIQ);
future.onSuccess(new SuccessCallback<IQ>() {
@Override
public void onSuccess(IQ result) {
enabled_state = use;
}
}
}).onError(exceptionCallback);
}
/**

View file

@ -35,13 +35,13 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.AbstractConnectionListener;
import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ExceptionCallback;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.FeatureNotSupportedException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackException.NotLoggedInException;
import org.jivesoftware.smack.SmackFuture;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry;
@ -63,7 +63,9 @@ import org.jivesoftware.smack.roster.packet.RosterPacket.Item;
import org.jivesoftware.smack.roster.packet.RosterVer;
import org.jivesoftware.smack.roster.packet.SubscriptionPreApproval;
import org.jivesoftware.smack.roster.rosterstore.RosterStore;
import org.jivesoftware.smack.util.ExceptionCallback;
import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.SuccessCallback;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.EntityBareJid;
@ -428,7 +430,11 @@ public final class Roster extends Manager {
packet.setVersion(rosterStore.getRosterVersion());
}
rosterState = RosterState.loading;
connection.sendIqWithResponseCallback(packet, new RosterResultListener(), new ExceptionCallback() {
SmackFuture<IQ, Exception> future = connection.sendIqRequestAsync(packet);
future.onSuccess(new RosterResultListener()).onError(new ExceptionCallback<Exception>() {
@Override
public void processException(Exception exception) {
rosterState = RosterState.uninitialized;
@ -438,11 +444,12 @@ public final class Roster extends Manager {
} else {
logLevel = Level.SEVERE;
}
LOGGER.log(logLevel, "Exception reloading roster" , exception);
LOGGER.log(logLevel, "Exception reloading roster", exception);
for (RosterLoadedListener listener : rosterLoadedListeners) {
listener.onRosterLoadingFailed(exception);
}
}
});
}
@ -1565,10 +1572,10 @@ public final class Roster extends Manager {
/**
* Handles Roster results as described in <a href="https://tools.ietf.org/html/rfc6121#section-2.1.4">RFC 6121 2.1.4</a>.
*/
private class RosterResultListener implements StanzaListener {
private class RosterResultListener implements SuccessCallback<IQ> {
@Override
public void processStanza(Stanza packet) {
public void onSuccess(IQ packet) {
final XMPPConnection connection = connection();
LOGGER.log(Level.FINE, "RosterResultListener received {}", packet);
Collection<Jid> addedEntries = new ArrayList<>();