1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 09:09:38 +02: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

@ -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);
}
/**