mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 19:47:58 +01:00
Use CopyOnWriteArraySet in InvitationsMonitor
This commit is contained in:
parent
ccdd94c997
commit
5f06234149
1 changed files with 6 additions and 17 deletions
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue