From 0408d075b721c056db91911a1a1a718867430cbc Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 30 Oct 2014 23:36:40 +0100 Subject: [PATCH] Merge invokePacketCollectors() and notifiyReceivedListeners() into invokePacketCollectorsAndNotifyRecvListeners() --- .../smack/AbstractXMPPConnection.java | 61 +++++++++---------- .../jivesoftware/smack/DummyConnection.java | 9 +-- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index eea28bc93..a6b59f827 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -821,19 +821,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { packetReplyTimeout = timeout; } - /** - * Invoke {@link PacketCollector#processPacket(Packet)} for every - * PacketCollector with the given packet. - * - * @param packet the packet to notify the PacketCollectors about. - */ - protected void invokePacketCollectors(Packet packet) { - // Loop through all collectors and notify the appropriate ones. - for (PacketCollector collector: collectors) { - collector.processPacket(packet); - } - } - /** * Processes a packet after it's been fully parsed by looping through the installed * packet collectors and listeners and letting them examine the packet to see if @@ -846,7 +833,36 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { executorService.submit(new ListenerNotification(packet)); } - protected void notifiyReceivedListeners(Packet packet) { + /** + * A runnable to notify all listeners and packet collectors of a packet. + */ + private class ListenerNotification implements Runnable { + + private final Packet packet; + + public ListenerNotification(Packet packet) { + this.packet = packet; + } + + public void run() { + invokePacketCollectorsAndNotifyRecvListeners(packet); + } + } + + + /** + * Invoke {@link PacketCollector#processPacket(Packet)} for every + * PacketCollector with the given packet. Also notify the receive listeners with a matching packet filter about the packet. + * + * @param packet the packet to notify the PacketCollectors and receive listeners about. + */ + protected void invokePacketCollectorsAndNotifyRecvListeners(Packet packet) { + // Loop through all collectors and notify the appropriate ones. + for (PacketCollector collector: collectors) { + collector.processPacket(packet); + } + + // Notify the receive listeners interested in the packet List listenersToNotify = new LinkedList(); synchronized (recvListeners) { for (ListenerWrapper listenerWrapper : recvListeners.values()) { @@ -868,23 +884,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } } - /** - * A runnable to notify all listeners and packet collectors of a packet. - */ - private class ListenerNotification implements Runnable { - - private final Packet packet; - - public ListenerNotification(Packet packet) { - this.packet = packet; - } - - public void run() { - invokePacketCollectors(packet); - notifiyReceivedListeners(packet); - } - } - /** * Sets whether the connection has already logged in the server. This method assures that the * {@link #wasAuthenticated} flag is never reset once it has ever been set. diff --git a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java index 09b1d0971..725329c6c 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java @@ -238,17 +238,10 @@ public class DummyConnection extends AbstractXMPPConnection { * @param packet the packet to process. */ public void processPacket(Packet packet) { - if (packet == null) { - return; - } - - invokePacketCollectors(packet); - if (SmackConfiguration.DEBUG_ENABLED) { System.out.println("[RECV]: " + packet.toXML()); } - // Deliver the incoming packet to listeners. - notifiyReceivedListeners(packet); + invokePacketCollectorsAndNotifyRecvListeners(packet); } }