1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-08 14:11:07 +01:00

s/processPacket/processStanza/ s/PacketCollector/StanzaCollector/

This commit is contained in:
Florian Schmaus 2017-01-03 11:12:34 +01:00
parent 9328182912
commit 90a5e289f8
100 changed files with 406 additions and 406 deletions

View file

@ -111,17 +111,17 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
new CopyOnWriteArraySet<ConnectionListener>();
/**
* A collection of PacketCollectors which collects packets for a specified filter
* A collection of StanzaCollectors which collects packets for a specified filter
* and perform blocking and polling operations on the result queue.
* <p>
* We use a ConcurrentLinkedQueue here, because its Iterator is weakly
* consistent and we want {@link #invokePacketCollectors(Stanza)} for-each
* loop to be lock free. As drawback, removing a PacketCollector is O(n).
* consistent and we want {@link #invokeStanzaCollectorsAndNotifyRecvListeners(Stanza)} for-each
* loop to be lock free. As drawback, removing a StanzaCollector is O(n).
* The alternative would be a synchronized HashSet, but this would mean a
* synchronized block around every usage of <code>collectors</code>.
* </p>
*/
private final Collection<PacketCollector> collectors = new ConcurrentLinkedQueue<PacketCollector>();
private final Collection<StanzaCollector> collectors = new ConcurrentLinkedQueue<>();
/**
* List of PacketListeners that will be notified synchronously when a new stanza(/packet) was received.
@ -531,7 +531,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
// Note that we can not use IQReplyFilter here, since the users full JID is not yet
// available. It will become available right after the resource has been successfully bound.
Bind bindResource = Bind.newSet(resource);
PacketCollector packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
StanzaCollector packetCollector = createStanzaCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
Bind response = packetCollector.nextResultOrThrow();
// Set the connections user to the result of resource binding. It is important that we don't infer the user
// from the login() arguments and the configurations service name, as, for example, when SASL External is used,
@ -547,7 +547,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
boolean legacySessionDisabled = getConfiguration().isLegacySessionDisabled();
if (sessionFeature != null && !sessionFeature.isOptional() && !legacySessionDisabled) {
Session session = new Session();
packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(session), session);
packetCollector = createStanzaCollectorAndSend(new StanzaIdFilter(session), session);
packetCollector.nextResultOrThrow();
}
}
@ -743,18 +743,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
@Override
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException {
public StanzaCollector createStanzaCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException {
StanzaFilter packetFilter = new IQReplyFilter(packet, this);
// Create the packet collector before sending the packet
PacketCollector packetCollector = createPacketCollectorAndSend(packetFilter, packet);
StanzaCollector packetCollector = createStanzaCollectorAndSend(packetFilter, packet);
return packetCollector;
}
@Override
public PacketCollector createPacketCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
public StanzaCollector createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
throws NotConnectedException, InterruptedException {
// Create the packet collector before sending the packet
PacketCollector packetCollector = createPacketCollector(packetFilter);
StanzaCollector packetCollector = createStanzaCollector(packetFilter);
try {
// Now we can send the packet as the collector has been created
sendStanza(packet);
@ -767,21 +767,21 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
@Override
public PacketCollector createPacketCollector(StanzaFilter packetFilter) {
PacketCollector.Configuration configuration = PacketCollector.newConfiguration().setStanzaFilter(packetFilter);
return createPacketCollector(configuration);
public StanzaCollector createStanzaCollector(StanzaFilter packetFilter) {
StanzaCollector.Configuration configuration = StanzaCollector.newConfiguration().setStanzaFilter(packetFilter);
return createStanzaCollector(configuration);
}
@Override
public PacketCollector createPacketCollector(PacketCollector.Configuration configuration) {
PacketCollector collector = new PacketCollector(this, configuration);
public StanzaCollector createStanzaCollector(StanzaCollector.Configuration configuration) {
StanzaCollector collector = new StanzaCollector(this, configuration);
// Add the collector to the list of active collectors.
collectors.add(collector);
return collector;
}
@Override
public void removePacketCollector(PacketCollector collector) {
public void removeStanzaCollector(StanzaCollector collector) {
collectors.remove(collector);
}
@ -878,7 +878,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
public void run() {
for (StanzaListener listener : listenersToNotify) {
try {
listener.processPacket(packet);
listener.processStanza(packet);
}
catch (Exception e) {
LOGGER.log(Level.WARNING, "Sending listener threw exception", e);
@ -926,7 +926,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
for (StanzaListener interceptor : interceptorsToInvoke) {
try {
interceptor.processPacket(packet);
interceptor.processStanza(packet);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Packet interceptor threw exception", e);
}
@ -1033,18 +1033,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
executorService.executeBlocking(new Runnable() {
@Override
public void run() {
invokePacketCollectorsAndNotifyRecvListeners(stanza);
invokeStanzaCollectorsAndNotifyRecvListeners(stanza);
}
});
}
/**
* Invoke {@link PacketCollector#processPacket(Stanza)} for every
* PacketCollector with the given packet. Also notify the receive listeners with a matching stanza(/packet) filter about the packet.
* Invoke {@link StanzaCollector#processStanza(Stanza)} for every
* StanzaCollector with the given packet. Also notify the receive listeners with a matching stanza(/packet) filter about the packet.
*
* @param packet the stanza(/packet) to notify the PacketCollectors and receive listeners about.
* @param packet the stanza(/packet) to notify the StanzaCollectors and receive listeners about.
*/
protected void invokePacketCollectorsAndNotifyRecvListeners(final Stanza packet) {
protected void invokeStanzaCollectorsAndNotifyRecvListeners(final Stanza packet) {
if (packet instanceof IQ) {
final IQ iq = (IQ) packet;
final IQ.Type type = iq.getType();
@ -1140,7 +1140,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
@Override
public void run() {
try {
listener.processPacket(packet);
listener.processStanza(packet);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Exception in async packet listener", e);
}
@ -1149,8 +1149,8 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
}
// Loop through all collectors and notify the appropriate ones.
for (PacketCollector collector: collectors) {
collector.processPacket(packet);
for (StanzaCollector collector: collectors) {
collector.processStanza(packet);
}
// Notify the receive listeners interested in the packet
@ -1170,7 +1170,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
public void run() {
for (StanzaListener listener : listenersToNotify) {
try {
listener.processPacket(packet);
listener.processStanza(packet);
} catch(NotConnectedException e) {
LOGGER.log(Level.WARNING, "Got not connected exception, aborting", e);
break;
@ -1471,10 +1471,10 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
final StanzaListener packetListener = new StanzaListener() {
@Override
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
try {
XMPPErrorException.ifHasErrorThenThrow(packet);
callback.processPacket(packet);
callback.processStanza(packet);
}
catch (XMPPErrorException e) {
if (exceptionCallback != null) {
@ -1532,9 +1532,9 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
public void addOneTimeSyncCallback(final StanzaListener callback, final StanzaFilter packetFilter) {
final StanzaListener packetListener = new StanzaListener() {
@Override
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException {
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException {
try {
callback.processPacket(packet);
callback.processStanza(packet);
} finally {
removeSyncStanzaListener(this);
}

View file

@ -129,7 +129,7 @@ public final class SmackConfiguration {
*
* @return The number of packets to queue before deleting older packets.
*/
public static int getPacketCollectorSize() {
public static int getStanzaCollectorSize() {
return packetCollectorSize;
}
@ -139,7 +139,7 @@ public final class SmackConfiguration {
*
* @param collectorSize the number of packets to queue before deleting older packets.
*/
public static void setPacketCollectorSize(int collectorSize) {
public static void setStanzaCollectorSize(int collectorSize) {
packetCollectorSize = collectorSize;
}

View file

@ -93,7 +93,7 @@ public class SmackException extends Exception {
}
public static NoResponseException newWith(XMPPConnection connection,
PacketCollector collector) {
StanzaCollector collector) {
return newWith(connection, collector.getStanzaFilter());
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software.
* Copyright 2003-2007 Jive Software, 2016-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.
@ -27,20 +27,20 @@ import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.packet.Stanza;
/**
* Provides a mechanism to collect packets into a result queue that pass a
* specified filter. The collector lets you perform blocking and polling
* operations on the result queue. So, a PacketCollector is more suitable to
* Provides a mechanism to collect Stanzas into a result queue that pass a
* specified filter/matcher. The collector lets you perform blocking and polling
* operations on the result queue. So, a StanzaCollector is more suitable to
* use than a {@link StanzaListener} when you need to wait for a specific
* result.<p>
*
* Each stanza(/packet) collector will queue up a configured number of packets for processing before
* older packets are automatically dropped. The default number is retrieved by
* {@link SmackConfiguration#getPacketCollectorSize()}.
* {@link SmackConfiguration#getStanzaCollectorSize()}.
*
* @see XMPPConnection#createPacketCollector(StanzaFilter)
* @see XMPPConnection#createStanzaCollector(StanzaFilter)
* @author Matt Tucker
*/
public class PacketCollector {
public class StanzaCollector {
private final StanzaFilter packetFilter;
@ -49,7 +49,7 @@ public class PacketCollector {
/**
* The stanza(/packet) collector which timeout for the next result will get reset once this collector collects a stanza.
*/
private final PacketCollector collectorToReset;
private final StanzaCollector collectorToReset;
private final XMPPConnection connection;
@ -62,7 +62,7 @@ public class PacketCollector {
* @param connection the connection the collector is tied to.
* @param configuration the configuration used to construct this collector
*/
protected PacketCollector(XMPPConnection connection, Configuration configuration) {
protected StanzaCollector(XMPPConnection connection, Configuration configuration) {
this.connection = connection;
this.packetFilter = configuration.packetFilter;
this.resultQueue = new ArrayBlockingQueue<>(configuration.size);
@ -78,7 +78,7 @@ public class PacketCollector {
// If the packet collector has already been cancelled, do nothing.
if (!cancelled) {
cancelled = true;
connection.removePacketCollector(this);
connection.removeStanzaCollector(this);
}
}
@ -274,7 +274,7 @@ public class PacketCollector {
*
* @param packet the stanza(/packet) to process.
*/
protected void processPacket(Stanza packet) {
protected void processStanza(Stanza packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
// CHECKSTYLE:OFF
while (!resultQueue.offer(packet)) {
@ -305,8 +305,8 @@ public class PacketCollector {
public static final class Configuration {
private StanzaFilter packetFilter;
private int size = SmackConfiguration.getPacketCollectorSize();
private PacketCollector collectorToReset;
private int size = SmackConfiguration.getStanzaCollectorSize();
private StanzaCollector collectorToReset;
private Configuration() {
}
@ -355,7 +355,7 @@ public class PacketCollector {
* @param collector
* @return a reference to this configuration.
*/
public Configuration setCollectorToReset(PacketCollector collector) {
public Configuration setCollectorToReset(StanzaCollector collector) {
this.collectorToReset = collector;
return this;
}

View file

@ -23,8 +23,8 @@ import org.jivesoftware.smack.packet.Stanza;
/**
* Provides a mechanism to listen for packets that pass a specified filter.
* This allows event-style programming -- every time a new stanza(/packet) is found,
* the {@link #processPacket(Stanza)} method will be called. This is the
* opposite approach to the functionality provided by a {@link PacketCollector}
* the {@link #processStanza(Stanza)} method will be called. This is the
* opposite approach to the functionality provided by a {@link StanzaCollector}
* which lets you block while waiting for results.
* <p>
* Additionally you are able to intercept Packets that are going to be send and
@ -50,6 +50,6 @@ public interface StanzaListener {
* @throws NotConnectedException
* @throws InterruptedException
*/
public void processPacket(Stanza packet) throws NotConnectedException, InterruptedException;
public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException;
}

View file

@ -225,11 +225,11 @@ public interface XMPPConnection {
* @throws NotConnectedException
* @throws InterruptedException
*/
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException;
public StanzaCollector createStanzaCollectorAndSend(IQ packet) throws NotConnectedException, InterruptedException;
/**
* Creates a new stanza(/packet) collector for this connection. A stanza(/packet) filter determines
* which packets will be accumulated by the collector. A PacketCollector is
* which packets will be accumulated by the collector. A StanzaCollector is
* more suitable to use than a {@link StanzaListener} when you need to wait for
* a specific result.
*
@ -239,46 +239,46 @@ public interface XMPPConnection {
* @throws InterruptedException
* @throws NotConnectedException
*/
public PacketCollector createPacketCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
public StanzaCollector createStanzaCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
throws NotConnectedException, InterruptedException;
/**
* Creates a new stanza(/packet) collector for this connection. A stanza(/packet) filter
* determines which packets will be accumulated by the collector. A
* PacketCollector is more suitable to use than a {@link StanzaListener}
* StanzaCollector is more suitable to use than a {@link StanzaListener}
* when you need to wait for a specific result.
* <p>
* <b>Note:</b> If you send a Stanza(/Packet) right after using this method, then
* consider using
* {@link #createPacketCollectorAndSend(StanzaFilter, Stanza)} instead.
* Otherwise make sure cancel the PacketCollector in every case, e.g. even
* if an exception is thrown, or otherwise you may leak the PacketCollector.
* {@link #createStanzaCollectorAndSend(StanzaFilter, Stanza)} instead.
* Otherwise make sure cancel the StanzaCollector in every case, e.g. even
* if an exception is thrown, or otherwise you may leak the StanzaCollector.
* </p>
*
* @param packetFilter the stanza(/packet) filter to use.
* @return a new stanza(/packet) collector.
*/
public PacketCollector createPacketCollector(StanzaFilter packetFilter);
public StanzaCollector createStanzaCollector(StanzaFilter packetFilter);
/**
* Create a new stanza(/packet) collector with the given stanza(/packet) collector configuration.
* <p>
* Please make sure to cancel the collector when it is no longer required. See also
* {@link #createPacketCollector(StanzaFilter)}.
* {@link #createStanzaCollector(StanzaFilter)}.
* </p>
*
* @param configuration the stanza(/packet) collector configuration.
* @return a new stanza(/packet) collector.
* @since 4.1
*/
public PacketCollector createPacketCollector(PacketCollector.Configuration configuration);
public StanzaCollector createStanzaCollector(StanzaCollector.Configuration configuration);
/**
* Remove a stanza(/packet) collector of this connection.
*
* @param collector a stanza(/packet) collectors which was created for this connection.
*/
public void removePacketCollector(PacketCollector collector);
public void removeStanzaCollector(StanzaCollector collector);
/**
* Registers a stanza(/packet) listener with this connection.
@ -316,7 +316,7 @@ public interface XMPPConnection {
* incoming stanzas. Only use this kind of stanza(/packet) filter if it does not perform any XMPP activity that waits for a
* response. Consider using {@link #addAsyncStanzaListener(StanzaListener, StanzaFilter)} when possible, i.e. when
* the invocation order doesn't have to be the same as the order of the arriving packets. If the order of the
* arriving packets, consider using a {@link PacketCollector} when possible.
* arriving packets, consider using a {@link StanzaCollector} when possible.
* </p>
*
* @param packetListener the stanza(/packet) listener to notify of new received packets.

View file

@ -68,7 +68,7 @@ public abstract class AbstractDebugger implements SmackDebugger {
// the GUI. This is what we call "interpreted" packet data, since it's the packet
// data as Smack sees it and not as it's coming in as raw XML.
listener = new StanzaListener() {
public void processPacket(Stanza packet) {
public void processStanza(Stanza packet) {
if (printInterpreted) {
log("RCV PKT (" + connection.getConnectionCounter() + "): " + packet.toXML());
}

View file

@ -37,10 +37,10 @@ package org.jivesoftware.smack.filter;
* }
* };
* // Create a new stanza(/packet) collector using the filter we created.
* PacketCollector myCollector = packetReader.createPacketCollector(myFilter);
* StanzaCollector myCollector = packetReader.createStanzaCollector(myFilter);
* </pre>
*
* @see org.jivesoftware.smack.PacketCollector
* @see org.jivesoftware.smack.StanzaCollector
* @see org.jivesoftware.smack.StanzaListener
* @author Matt Tucker
* @deprecated use {@link StanzaFilter}

View file

@ -39,10 +39,10 @@ import org.jivesoftware.smack.packet.Stanza;
* }
* };
* // Create a new stanza collector using the filter we created.
* PacketCollector myCollector = connection.createPacketCollector(myFilter);
* StanzaCollector myCollector = connection.createStanzaCollector(myFilter);
* </pre>
*
* @see org.jivesoftware.smack.PacketCollector
* @see org.jivesoftware.smack.StanzaCollector
* @see org.jivesoftware.smack.StanzaListener
* @author Matt Tucker
*/

View file

@ -16,6 +16,6 @@
*/
/**
* Allows {@link org.jivesoftware.smack.PacketCollector} and {@link org.jivesoftware.smack.StanzaListener} instances to filter for stanzas with particular attributes.
* Allows {@link org.jivesoftware.smack.StanzaCollector} and {@link org.jivesoftware.smack.StanzaListener} instances to filter for stanzas with particular attributes.
*/
package org.jivesoftware.smack.filter;