mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 00:02:06 +01:00
Fixed listener remove operation.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1866 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
7bac4581e3
commit
d77787f67c
1 changed files with 22 additions and 7 deletions
|
@ -144,7 +144,6 @@ class PacketReader {
|
||||||
*/
|
*/
|
||||||
public PacketCollector createPacketCollector(PacketFilter packetFilter) {
|
public PacketCollector createPacketCollector(PacketFilter packetFilter) {
|
||||||
PacketCollector packetCollector = new PacketCollector(this, packetFilter);
|
PacketCollector packetCollector = new PacketCollector(this, packetFilter);
|
||||||
|
|
||||||
return packetCollector;
|
return packetCollector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,14 +163,18 @@ class PacketReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a packet listener from this reader.
|
* Removes a packet listener.
|
||||||
*
|
*
|
||||||
* @param packetListener the packet listener to remove.
|
* @param packetListener the packet listener to remove.
|
||||||
*/
|
*/
|
||||||
public void removePacketListener(PacketListener packetListener) {
|
public void removePacketListener(PacketListener packetListener) {
|
||||||
synchronized (listeners) {
|
synchronized (listeners) {
|
||||||
int index = listeners.indexOf(packetListener);
|
for (int i=0; i<listeners.size(); i++) {
|
||||||
listeners.set(index, null);
|
ListenerWrapper wrapper = (ListenerWrapper)listeners.get(i);
|
||||||
|
if (wrapper.packetListener.equals(packetListener)) {
|
||||||
|
listeners.set(i, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,8 +219,13 @@ class PacketReader {
|
||||||
boolean processedPacket = false;
|
boolean processedPacket = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
synchronized (listeners) {
|
synchronized (listeners) {
|
||||||
// TODO: need to loop through lists and remove null elements. Should loop through
|
if (listeners.size() > 0) {
|
||||||
// TODO: list backwards so that index values stay correct.
|
for (int i=listeners.size()-1; i>=0; i--) {
|
||||||
|
if (listeners.get(i) == null) {
|
||||||
|
listeners.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
processedPacket = false;
|
processedPacket = false;
|
||||||
int size = listeners.size();
|
int size = listeners.size();
|
||||||
|
@ -300,7 +308,14 @@ class PacketReader {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: loop through collectors and remove null values.
|
// Remove all null values from the collectors list.
|
||||||
|
synchronized (collectors) {
|
||||||
|
for (int i=collectors.size()-1; i<=0; i--) {
|
||||||
|
if (collectors.get(i) == null) {
|
||||||
|
collectors.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Loop through all collectors and notify the appropriate ones.
|
// Loop through all collectors and notify the appropriate ones.
|
||||||
int size = collectors.size();
|
int size = collectors.size();
|
||||||
|
|
Loading…
Reference in a new issue