1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-29 09:42: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.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -2350,9 +2351,7 @@ public class MultiUserChat {
private static final PacketFilter invitationFilter = new PacketExtensionFilter(new MUCUser()); 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 Set<InvitationListener> invitationsListeners = new CopyOnWriteArraySet<InvitationListener>();
private final List<InvitationListener> invitationsListeners =
new ArrayList<InvitationListener>();
private final PacketListener invitationPacketListener; private final PacketListener invitationPacketListener;
/** /**
@ -2403,11 +2402,7 @@ public class MultiUserChat {
* @param listener an invitation listener. * @param listener an invitation listener.
*/ */
public void addInvitationListener(InvitationListener listener) { public void addInvitationListener(InvitationListener listener) {
synchronized (invitationsListeners) { invitationsListeners.add(listener);
if (!invitationsListeners.contains(listener)) {
invitationsListeners.add(listener);
}
}
} }
/** /**
@ -2417,11 +2412,7 @@ public class MultiUserChat {
* @param listener an invitation listener. * @param listener an invitation listener.
*/ */
public void removeInvitationListener(InvitationListener listener) { public void removeInvitationListener(InvitationListener listener) {
synchronized (invitationsListeners) { invitationsListeners.remove(listener);
if (invitationsListeners.contains(listener)) {
invitationsListeners.remove(listener);
}
}
} }
/** /**
@ -2429,10 +2420,8 @@ public class MultiUserChat {
*/ */
private void fireInvitationListeners(String room, String inviter, String reason, String password, private void fireInvitationListeners(String room, String inviter, String reason, String password,
Message message) { Message message) {
synchronized (invitationsListeners) { for (InvitationListener listener : invitationsListeners) {
for (InvitationListener listener : invitationsListeners) { listener.invitationReceived(connection(), room, inviter, reason, password, message);
listener.invitationReceived(connection(), room, inviter, reason, password, message);
}
} }
} }
} }