mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 16:22:06 +01:00
Another collection change.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7168 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
7ebaba10e2
commit
e155c302ad
1 changed files with 9 additions and 16 deletions
|
@ -31,9 +31,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for XML traffic from the XMPP server and parses it into packet objects.
|
* Listens for XML traffic from the XMPP server and parses it into packet objects.
|
||||||
|
@ -51,9 +49,9 @@ class PacketReader {
|
||||||
private XMPPConnection connection;
|
private XMPPConnection connection;
|
||||||
private XmlPullParser parser;
|
private XmlPullParser parser;
|
||||||
private boolean done;
|
private boolean done;
|
||||||
private List<PacketCollector> collectors = new CopyOnWriteArrayList<PacketCollector>();
|
private Collection<PacketCollector> collectors = new ConcurrentLinkedQueue<PacketCollector>();
|
||||||
protected final List<ListenerWrapper> listeners = new CopyOnWriteArrayList<ListenerWrapper>();
|
protected final Map<PacketListener, ListenerWrapper> listeners = new ConcurrentHashMap<PacketListener, ListenerWrapper>();
|
||||||
protected final List<ConnectionListener> connectionListeners =
|
protected final Collection<ConnectionListener> connectionListeners =
|
||||||
new CopyOnWriteArrayList<ConnectionListener>();
|
new CopyOnWriteArrayList<ConnectionListener>();
|
||||||
|
|
||||||
private String connectionID = null;
|
private String connectionID = null;
|
||||||
|
@ -123,7 +121,7 @@ class PacketReader {
|
||||||
*/
|
*/
|
||||||
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
|
public void addPacketListener(PacketListener packetListener, PacketFilter packetFilter) {
|
||||||
ListenerWrapper wrapper = new ListenerWrapper(this, packetListener, packetFilter);
|
ListenerWrapper wrapper = new ListenerWrapper(this, packetListener, packetFilter);
|
||||||
listeners.add(wrapper);
|
listeners.put(packetListener, wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,15 +130,10 @@ class PacketReader {
|
||||||
* @param packetListener the packet listener to remove.
|
* @param packetListener the packet listener to remove.
|
||||||
*/
|
*/
|
||||||
public void removePacketListener(PacketListener packetListener) {
|
public void removePacketListener(PacketListener packetListener) {
|
||||||
// Find the index of the wrapper in the list of listeners. This operation will
|
ListenerWrapper wrapper = listeners.remove(packetListener);
|
||||||
// work because of a special equals() implementation in the ListenerWrapper class.
|
if (wrapper != null) {
|
||||||
int index = listeners.indexOf(packetListener);
|
wrapper.cancel();
|
||||||
if (index == -1) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
ListenerWrapper wrapper = listeners.remove(index);
|
|
||||||
// Cancel the wrapper since it's been removed.
|
|
||||||
wrapper.cancel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -285,7 +278,7 @@ class PacketReader {
|
||||||
private void processListeners(Thread thread) {
|
private void processListeners(Thread thread) {
|
||||||
while (!done && thread == listenerThread) {
|
while (!done && thread == listenerThread) {
|
||||||
boolean processedPacket = false;
|
boolean processedPacket = false;
|
||||||
for (ListenerWrapper wrapper: listeners) {
|
for (ListenerWrapper wrapper: listeners.values()) {
|
||||||
processedPacket = processedPacket || wrapper.notifyListener();
|
processedPacket = processedPacket || wrapper.notifyListener();
|
||||||
}
|
}
|
||||||
if (!processedPacket) {
|
if (!processedPacket) {
|
||||||
|
|
Loading…
Reference in a new issue