mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 00:02:06 +01:00
Merge invokePacketCollectors() and notifiyReceivedListeners()
into invokePacketCollectorsAndNotifyRecvListeners()
This commit is contained in:
parent
1de2fc2a81
commit
0408d075b7
2 changed files with 31 additions and 39 deletions
|
@ -821,19 +821,6 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
packetReplyTimeout = timeout;
|
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
|
* 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
|
* 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));
|
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>();
|
List<PacketListener> listenersToNotify = new LinkedList<PacketListener>();
|
||||||
synchronized (recvListeners) {
|
synchronized (recvListeners) {
|
||||||
for (ListenerWrapper listenerWrapper : recvListeners.values()) {
|
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
|
* 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.
|
* {@link #wasAuthenticated} flag is never reset once it has ever been set.
|
||||||
|
|
|
@ -238,17 +238,10 @@ public class DummyConnection extends AbstractXMPPConnection {
|
||||||
* @param packet the packet to process.
|
* @param packet the packet to process.
|
||||||
*/
|
*/
|
||||||
public void processPacket(Packet packet) {
|
public void processPacket(Packet packet) {
|
||||||
if (packet == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
invokePacketCollectors(packet);
|
|
||||||
|
|
||||||
if (SmackConfiguration.DEBUG_ENABLED) {
|
if (SmackConfiguration.DEBUG_ENABLED) {
|
||||||
System.out.println("[RECV]: " + packet.toXML());
|
System.out.println("[RECV]: " + packet.toXML());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deliver the incoming packet to listeners.
|
invokePacketCollectorsAndNotifyRecvListeners(packet);
|
||||||
notifiyReceivedListeners(packet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue