Allows to remove a connection listener while notifying that the connection is being closed. SMACK-162

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2386 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2004-09-24 20:40:51 +00:00 committed by gdombiak
parent 31b508cc9f
commit cd8f9f5682
1 changed files with 8 additions and 2 deletions

View File

@ -202,8 +202,11 @@ class PacketReader {
public void shutdown() {
// Notify connection listeners of the connection closing if done hasn't already been set.
if (!done) {
ArrayList listenersCopy;
synchronized (connectionListeners) {
for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) {
// Make a copy since it's possible that a listener will be removed from the list
listenersCopy = new ArrayList(connectionListeners);
for (Iterator i=listenersCopy.iterator(); i.hasNext(); ) {
ConnectionListener listener = (ConnectionListener)i.next();
listener.connectionClosed();
}
@ -222,8 +225,11 @@ class PacketReader {
done = true;
connection.close();
// Notify connection listeners of the error.
ArrayList listenersCopy;
synchronized (connectionListeners) {
for (Iterator i=connectionListeners.iterator(); i.hasNext(); ) {
// Make a copy since it's possible that a listener will be removed from the list
listenersCopy = new ArrayList(connectionListeners);
for (Iterator i=listenersCopy.iterator(); i.hasNext(); ) {
ConnectionListener listener = (ConnectionListener)i.next();
listener.connectionClosedOnError(e);
}