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

Use CopyOnWriteArraySet in InvitationsMonitor

This commit is contained in:
Florian Schmaus 2014-10-05 12:46:51 +02:00
parent ccdd94c997
commit 5f06234149

View file

@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -2350,9 +2351,7 @@ public class MultiUserChat {
private static final PacketFilter invitationFilter = new PacketExtensionFilter(new MUCUser());
// We don't use a synchronized List here because it would break the semantic of (add|remove)InvitationListener
private final List<InvitationListener> invitationsListeners =
new ArrayList<InvitationListener>();
private final Set<InvitationListener> invitationsListeners = new CopyOnWriteArraySet<InvitationListener>();
private final PacketListener invitationPacketListener;
/**
@ -2403,12 +2402,8 @@ public class MultiUserChat {
* @param listener an invitation listener.
*/
public void addInvitationListener(InvitationListener listener) {
synchronized (invitationsListeners) {
if (!invitationsListeners.contains(listener)) {
invitationsListeners.add(listener);
}
}
}
/**
* Removes a listener to invitation notifications. The listener will be fired anytime
@ -2417,23 +2412,17 @@ public class MultiUserChat {
* @param listener an invitation listener.
*/
public void removeInvitationListener(InvitationListener listener) {
synchronized (invitationsListeners) {
if (invitationsListeners.contains(listener)) {
invitationsListeners.remove(listener);
}
}
}
/**
* Fires invitation listeners.
*/
private void fireInvitationListeners(String room, String inviter, String reason, String password,
Message message) {
synchronized (invitationsListeners) {
for (InvitationListener listener : invitationsListeners) {
listener.invitationReceived(connection(), room, inviter, reason, password, message);
}
}
}
}
}