1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Rename and deprecate XMPPConnection methods

Rename and deprecate XMPPConnections methods as described in SMACK-802
This commit is contained in:
Jesus Fuentes 2018-02-28 08:02:55 -06:00
parent 72a2014572
commit a70063dc89
15 changed files with 103 additions and 23 deletions

View file

@ -168,7 +168,7 @@ public class XMPPBOSHConnection extends AbstractXMPPConnection {
addAsyncStanzaListener(debugger.getReaderListener(), null); addAsyncStanzaListener(debugger.getReaderListener(), null);
} }
if (debugger.getWriterListener() != null) { if (debugger.getWriterListener() != null) {
addPacketSendingListener(debugger.getWriterListener(), null); addStanzaSendingListener(debugger.getWriterListener(), null);
} }
} }
} }

View file

@ -840,8 +840,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
@Deprecated
@Override @Override
public void addPacketSendingListener(StanzaListener packetListener, StanzaFilter packetFilter) { public void addPacketSendingListener(StanzaListener packetListener, StanzaFilter packetFilter) {
addStanzaSendingListener(packetListener, packetFilter);
}
@Override
public void addStanzaSendingListener(StanzaListener packetListener, StanzaFilter packetFilter) {
if (packetListener == null) { if (packetListener == null) {
throw new NullPointerException("Packet listener is null."); throw new NullPointerException("Packet listener is null.");
} }
@ -851,8 +857,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
@Deprecated
@Override @Override
public void removePacketSendingListener(StanzaListener packetListener) { public void removePacketSendingListener(StanzaListener packetListener) {
removeStanzaSendingListener(packetListener);
}
@Override
public void removeStanzaSendingListener(StanzaListener packetListener) {
synchronized (sendListeners) { synchronized (sendListeners) {
sendListeners.remove(packetListener); sendListeners.remove(packetListener);
} }
@ -896,8 +908,15 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}); });
} }
@Deprecated
@Override @Override
public void addPacketInterceptor(StanzaListener packetInterceptor, public void addPacketInterceptor(StanzaListener packetInterceptor,
StanzaFilter packetFilter) {
addStanzaInterceptor(packetInterceptor, packetFilter);
}
@Override
public void addStanzaInterceptor(StanzaListener packetInterceptor,
StanzaFilter packetFilter) { StanzaFilter packetFilter) {
if (packetInterceptor == null) { if (packetInterceptor == null) {
throw new NullPointerException("Packet interceptor is null."); throw new NullPointerException("Packet interceptor is null.");
@ -908,8 +927,14 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
} }
} }
@Deprecated
@Override @Override
public void removePacketInterceptor(StanzaListener packetInterceptor) { public void removePacketInterceptor(StanzaListener packetInterceptor) {
removeStanzaInterceptor(packetInterceptor);
}
@Override
public void removeStanzaInterceptor(StanzaListener packetInterceptor) {
synchronized (interceptors) { synchronized (interceptors) {
interceptors.remove(packetInterceptor); interceptors.remove(packetInterceptor);
} }

View file

@ -30,7 +30,7 @@ import org.jivesoftware.smack.packet.Stanza;
* <p> * <p>
* Additionally you are able to intercept Packets that are going to be send and * Additionally you are able to intercept Packets that are going to be send and
* make modifications to them. You can register a PacketListener as interceptor * make modifications to them. You can register a PacketListener as interceptor
* by using {@link XMPPConnection#addPacketInterceptor(StanzaListener, * by using {@link XMPPConnection#addStanzaInterceptor(StanzaListener,
* org.jivesoftware.smack.filter.StanzaFilter)} * org.jivesoftware.smack.filter.StanzaFilter)}
* </p> * </p>
* *

View file

@ -319,7 +319,7 @@ public interface XMPPConnection {
* *
* @param packetListener the stanza(/packet) listener to notify of new received packets. * @param packetListener the stanza(/packet) listener to notify of new received packets.
* @param packetFilter the stanza(/packet) filter to use. * @param packetFilter the stanza(/packet) filter to use.
* @see #addPacketInterceptor(StanzaListener, StanzaFilter) * @see #addStanzaInterceptor(StanzaListener, StanzaFilter)
* @since 4.1 * @since 4.1
*/ */
public void addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter); public void addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter);
@ -345,7 +345,7 @@ public interface XMPPConnection {
* *
* @param packetListener the stanza(/packet) listener to notify of new received packets. * @param packetListener the stanza(/packet) listener to notify of new received packets.
* @param packetFilter the stanza(/packet) filter to use. * @param packetFilter the stanza(/packet) filter to use.
* @see #addPacketInterceptor(StanzaListener, StanzaFilter) * @see #addStanzaInterceptor(StanzaListener, StanzaFilter)
* @since 4.1 * @since 4.1
*/ */
public void addAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter); public void addAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter);
@ -369,15 +369,41 @@ public interface XMPPConnection {
* *
* @param packetListener the stanza(/packet) listener to notify of sent packets. * @param packetListener the stanza(/packet) listener to notify of sent packets.
* @param packetFilter the stanza(/packet) filter to use. * @param packetFilter the stanza(/packet) filter to use.
* @deprecated use {@link #addStanzaSendingListener} instead
*/ */
// TODO Remove in Smack 4.4
@Deprecated
public void addPacketSendingListener(StanzaListener packetListener, StanzaFilter packetFilter); public void addPacketSendingListener(StanzaListener packetListener, StanzaFilter packetFilter);
/**
* Registers a stanza(/packet) listener with this connection. The listener will be
* notified of every stanza(/packet) that this connection sends. A stanza(/packet) filter determines
* which packets will be delivered to the listener. Note that the thread
* that writes packets will be used to invoke the listeners. Therefore, each
* stanza(/packet) listener should complete all operations quickly or use a different
* thread for processing.
*
* @param packetListener the stanza(/packet) listener to notify of sent packets.
* @param packetFilter the stanza(/packet) filter to use.
*/
public void addStanzaSendingListener(StanzaListener packetListener, StanzaFilter packetFilter);
/**
* Removes a stanza(/packet) listener for sending packets from this connection.
*
* @param packetListener the stanza(/packet) listener to remove.
* @deprecated use {@link #removeStanzaSendingListener} instead
*/
// TODO Remove in Smack 4.4
@Deprecated
public void removePacketSendingListener(StanzaListener packetListener);
/** /**
* Removes a stanza(/packet) listener for sending packets from this connection. * Removes a stanza(/packet) listener for sending packets from this connection.
* *
* @param packetListener the stanza(/packet) listener to remove. * @param packetListener the stanza(/packet) listener to remove.
*/ */
public void removePacketSendingListener(StanzaListener packetListener); public void removeStanzaSendingListener(StanzaListener packetListener);
/** /**
* Registers a stanza(/packet) interceptor with this connection. The interceptor will be * Registers a stanza(/packet) interceptor with this connection. The interceptor will be
@ -387,18 +413,47 @@ public interface XMPPConnection {
* *
* <p> * <p>
* NOTE: For a similar functionality on incoming packets, see {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)}. * NOTE: For a similar functionality on incoming packets, see {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)}.
* </p>
*
* @param packetInterceptor the stanza(/packet) interceptor to notify of packets about to be sent.
* @param packetFilter the stanza(/packet) filter to use.
* @deprecated use {@link #addStanzaInterceptor} instead
*/
// TODO Remove in Smack 4.4
@Deprecated
public void addPacketInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter);
/**
* Registers a stanza(/packet) interceptor with this connection. The interceptor will be
* invoked every time a stanza(/packet) is about to be sent by this connection. Interceptors
* may modify the stanza(/packet) to be sent. A stanza(/packet) filter determines which packets
* will be delivered to the interceptor.
*
* <p>
* NOTE: For a similar functionality on incoming packets, see {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)}.
* </p>
* *
* @param packetInterceptor the stanza(/packet) interceptor to notify of packets about to be sent. * @param packetInterceptor the stanza(/packet) interceptor to notify of packets about to be sent.
* @param packetFilter the stanza(/packet) filter to use. * @param packetFilter the stanza(/packet) filter to use.
*/ */
public void addPacketInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter); public void addStanzaInterceptor(StanzaListener packetInterceptor, StanzaFilter packetFilter);
/**
* Removes a stanza(/packet) interceptor.
*
* @param packetInterceptor the stanza(/packet) interceptor to remove.
* @deprecated user {@link #removeStanzaInterceptor} instead
*/
// TODO Remove in Smack 4.4
@Deprecated
public void removePacketInterceptor(StanzaListener packetInterceptor);
/** /**
* Removes a stanza(/packet) interceptor. * Removes a stanza(/packet) interceptor.
* *
* @param packetInterceptor the stanza(/packet) interceptor to remove. * @param packetInterceptor the stanza(/packet) interceptor to remove.
*/ */
public void removePacketInterceptor(StanzaListener packetInterceptor); public void removeStanzaInterceptor(StanzaListener packetInterceptor);
/** /**
* Returns the current value of the reply timeout in milliseconds for request for this * Returns the current value of the reply timeout in milliseconds for request for this

View file

@ -1013,7 +1013,7 @@ public class EnhancedDebugger implements SmackDebugger {
void cancel() { void cancel() {
connection.removeConnectionListener(connListener); connection.removeConnectionListener(connListener);
connection.removeAsyncStanzaListener(packetReaderListener); connection.removeAsyncStanzaListener(packetReaderListener);
connection.removePacketSendingListener(packetWriterListener); connection.removeStanzaSendingListener(packetWriterListener);
((ObservableReader) reader).removeReaderListener(readerListener); ((ObservableReader) reader).removeReaderListener(readerListener);
((ObservableWriter) writer).removeWriterListener(writerListener); ((ObservableWriter) writer).removeWriterListener(writerListener);
messagesTable = null; messagesTable = null;

View file

@ -95,7 +95,7 @@ public final class StableUniqueStanzaIdManager extends Manager {
public synchronized void enable() { public synchronized void enable() {
ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(NAMESPACE); ServiceDiscoveryManager.getInstanceFor(connection()).addFeature(NAMESPACE);
StanzaFilter filter = new AndFilter(OUTGOING_FILTER, new NotFilter(OUTGOING_FILTER)); StanzaFilter filter = new AndFilter(OUTGOING_FILTER, new NotFilter(OUTGOING_FILTER));
connection().addPacketInterceptor(stanzaListener, filter); connection().addStanzaInterceptor(stanzaListener, filter);
} }
/** /**
@ -103,7 +103,7 @@ public final class StableUniqueStanzaIdManager extends Manager {
*/ */
public synchronized void disable() { public synchronized void disable() {
ServiceDiscoveryManager.getInstanceFor(connection()).removeFeature(NAMESPACE); ServiceDiscoveryManager.getInstanceFor(connection()).removeFeature(NAMESPACE);
connection().removePacketInterceptor(stanzaListener); connection().removeStanzaInterceptor(stanzaListener);
} }
/** /**

View file

@ -116,7 +116,7 @@ public final class ChatManager extends Manager {
} }
}, INCOMING_MESSAGE_FILTER); }, INCOMING_MESSAGE_FILTER);
connection.addPacketInterceptor(new StanzaListener() { connection.addStanzaInterceptor(new StanzaListener() {
@Override @Override
public void processStanza(Stanza stanza) throws NotConnectedException, InterruptedException { public void processStanza(Stanza stanza) throws NotConnectedException, InterruptedException {
Message message = (Message) stanza; Message message = (Message) stanza;

View file

@ -339,7 +339,7 @@ public final class EntityCapsManager extends Manager {
} }
}); });
connection.addPacketSendingListener(new StanzaListener() { connection.addStanzaSendingListener(new StanzaListener() {
@Override @Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
presenceSend = (Presence) packet; presenceSend = (Presence) packet;
@ -362,7 +362,7 @@ public final class EntityCapsManager extends Manager {
packet.overrideExtension(caps); packet.overrideExtension(caps);
} }
}; };
connection.addPacketInterceptor(packetInterceptor, PresenceTypeFilter.AVAILABLE); connection.addStanzaInterceptor(packetInterceptor, PresenceTypeFilter.AVAILABLE);
// It's important to do this as last action. Since it changes the // It's important to do this as last action. Since it changes the
// behavior of the SDM in some ways // behavior of the SDM in some ways
sdm.setEntityCapsManager(this); sdm.setEntityCapsManager(this);

View file

@ -134,7 +134,7 @@ public final class LastActivityManager extends Manager {
super(connection); super(connection);
// Listen to all the sent messages to reset the idle time on each one // Listen to all the sent messages to reset the idle time on each one
connection.addPacketSendingListener(new StanzaListener() { connection.addStanzaSendingListener(new StanzaListener() {
@Override @Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
Presence presence = (Presence) packet; Presence presence = (Presence) packet;
@ -153,7 +153,7 @@ public final class LastActivityManager extends Manager {
} }
}, StanzaTypeFilter.PRESENCE); }, StanzaTypeFilter.PRESENCE);
connection.addPacketSendingListener(new StanzaListener() { connection.addStanzaSendingListener(new StanzaListener() {
@Override @Override
public void processStanza(Stanza packet) { public void processStanza(Stanza packet) {
Message message = (Message) packet; Message message = (Message) packet;

View file

@ -334,7 +334,7 @@ public class MultiUserChat {
); );
// @formatter:on // @formatter:on
connection.addSyncStanzaListener(declinesListener, new AndFilter(fromRoomFilter, DECLINE_FILTER)); connection.addSyncStanzaListener(declinesListener, new AndFilter(fromRoomFilter, DECLINE_FILTER));
connection.addPacketInterceptor(presenceInterceptor, new AndFilter(ToMatchesFilter.create(room), connection.addStanzaInterceptor(presenceInterceptor, new AndFilter(ToMatchesFilter.create(room),
StanzaTypeFilter.PRESENCE)); StanzaTypeFilter.PRESENCE));
messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter); messageCollector = connection.createStanzaCollector(fromRoomGroupchatFilter);
@ -2021,7 +2021,7 @@ public class MultiUserChat {
connection.removeSyncStanzaListener(presenceListener); connection.removeSyncStanzaListener(presenceListener);
connection.removeSyncStanzaListener(subjectListener); connection.removeSyncStanzaListener(subjectListener);
connection.removeSyncStanzaListener(declinesListener); connection.removeSyncStanzaListener(declinesListener);
connection.removePacketInterceptor(presenceInterceptor); connection.removeStanzaInterceptor(presenceInterceptor);
if (messageCollector != null) { if (messageCollector != null) {
messageCollector.cancel(); messageCollector.cancel();
messageCollector = null; messageCollector = null;

View file

@ -126,7 +126,7 @@ public final class PrivacyListManager extends Manager {
}); });
// cached(Active|Default)ListName handling // cached(Active|Default)ListName handling
connection.addPacketSendingListener(new StanzaListener() { connection.addStanzaSendingListener(new StanzaListener() {
@Override @Override
public void processStanza(Stanza packet) throws NotConnectedException { public void processStanza(Stanza packet) throws NotConnectedException {
XMPPConnection connection = connection(); XMPPConnection connection = connection();
@ -148,7 +148,7 @@ public final class PrivacyListManager extends Manager {
}, iqResultReplyFilter); }, iqResultReplyFilter);
} }
}, SetActiveListFilter.INSTANCE); }, SetActiveListFilter.INSTANCE);
connection.addPacketSendingListener(new StanzaListener() { connection.addStanzaSendingListener(new StanzaListener() {
@Override @Override
public void processStanza(Stanza packet) throws NotConnectedException { public void processStanza(Stanza packet) throws NotConnectedException {
XMPPConnection connection = connection(); XMPPConnection connection = connection();

View file

@ -279,7 +279,7 @@ public final class DeliveryReceiptManager extends Manager {
* @see #dontAutoAddDeliveryReceiptRequests() * @see #dontAutoAddDeliveryReceiptRequests()
*/ */
public void autoAddDeliveryReceiptRequests() { public void autoAddDeliveryReceiptRequests() {
connection().addPacketInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER, connection().addStanzaInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER,
MESSAGES_TO_REQUEST_RECEIPTS_FOR); MESSAGES_TO_REQUEST_RECEIPTS_FOR);
} }
@ -290,7 +290,7 @@ public final class DeliveryReceiptManager extends Manager {
* @see #autoAddDeliveryReceiptRequests() * @see #autoAddDeliveryReceiptRequests()
*/ */
public void dontAutoAddDeliveryReceiptRequests() { public void dontAutoAddDeliveryReceiptRequests() {
connection().removePacketInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER); connection().removeStanzaInterceptor(AUTO_ADD_DELIVERY_RECEIPT_REQUESTS_LISTENER);
} }
/** /**

View file

@ -335,7 +335,7 @@ public final class Roster extends Manager {
}); });
connection.addPacketSendingListener(new StanzaListener() { connection.addStanzaSendingListener(new StanzaListener() {
@Override @Override
public void processStanza(Stanza stanzav) throws NotConnectedException, InterruptedException { public void processStanza(Stanza stanzav) throws NotConnectedException, InterruptedException {
// Once we send an unavailable presence, the server is allowed to suppress sending presence status // Once we send an unavailable presence, the server is allowed to suppress sending presence status

View file

@ -134,7 +134,7 @@ public class EntityCapsTest extends AbstractSmackIntegrationTest {
@SmackIntegrationTest @SmackIntegrationTest
public void testPreventDiscoInfo() throws Exception { public void testPreventDiscoInfo() throws Exception {
final String dummyFeature = getNewDummyFeature(); final String dummyFeature = getNewDummyFeature();
conOne.addPacketSendingListener(new StanzaListener() { conOne.addStanzaSendingListener(new StanzaListener() {
@Override @Override
public void processStanza(Stanza stanza) { public void processStanza(Stanza stanza) {

View file

@ -643,7 +643,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
if (config.isDebuggerEnabled()) { if (config.isDebuggerEnabled()) {
addAsyncStanzaListener(debugger.getReaderListener(), null); addAsyncStanzaListener(debugger.getReaderListener(), null);
if (debugger.getWriterListener() != null) { if (debugger.getWriterListener() != null) {
addPacketSendingListener(debugger.getWriterListener(), null); addStanzaSendingListener(debugger.getWriterListener(), null);
} }
} }
} }