mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 05:52:06 +01:00
Synchronize ChatStateManager's chatStateListeners
This commit is contained in:
parent
75babfb9c6
commit
9d53363413
1 changed files with 15 additions and 3 deletions
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
package org.jivesoftware.smackx.chatstates;
|
package org.jivesoftware.smackx.chatstates;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
@ -146,7 +148,13 @@ public final class ChatStateManager extends Manager {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ChatStateListener listener : chatStateListeners) {
|
List<ChatStateListener> listeners;
|
||||||
|
synchronized (chatStateListeners) {
|
||||||
|
listeners = new ArrayList<>(chatStateListeners.size());
|
||||||
|
listeners.addAll(chatStateListeners);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ChatStateListener listener : listeners) {
|
||||||
listener.stateChanged(chat, state, message);
|
listener.stateChanged(chat, state, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +170,9 @@ public final class ChatStateManager extends Manager {
|
||||||
* @return true, if the listener was not registered before
|
* @return true, if the listener was not registered before
|
||||||
*/
|
*/
|
||||||
public boolean addChatStateListener(ChatStateListener listener) {
|
public boolean addChatStateListener(ChatStateListener listener) {
|
||||||
return chatStateListeners.add(listener);
|
synchronized (chatStateListeners) {
|
||||||
|
return chatStateListeners.add(listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,7 +182,9 @@ public final class ChatStateManager extends Manager {
|
||||||
* @return true, if the listener was registered before
|
* @return true, if the listener was registered before
|
||||||
*/
|
*/
|
||||||
public boolean removeChatStateListener(ChatStateListener listener) {
|
public boolean removeChatStateListener(ChatStateListener listener) {
|
||||||
return chatStateListeners.remove(listener);
|
synchronized (chatStateListeners) {
|
||||||
|
return chatStateListeners.remove(listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue