mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 20:12:07 +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,8 +170,10 @@ 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) {
|
||||||
|
synchronized (chatStateListeners) {
|
||||||
return chatStateListeners.add(listener);
|
return chatStateListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister a ChatStateListener.
|
* Unregister a ChatStateListener.
|
||||||
|
@ -172,8 +182,10 @@ 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) {
|
||||||
|
synchronized (chatStateListeners) {
|
||||||
return chatStateListeners.remove(listener);
|
return chatStateListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue