1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-26 06:07:59 +01:00

Merge invokePacketCollectors() and notifiyReceivedListeners()

into invokePacketCollectorsAndNotifyRecvListeners()
This commit is contained in:
Florian Schmaus 2014-10-30 23:36:40 +01:00
parent 1de2fc2a81
commit 0408d075b7
2 changed files with 31 additions and 39 deletions

View file

@ -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<PacketListener> listenersToNotify = new LinkedList<PacketListener>();
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.

View file

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