1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-27 00:32:07 +01:00

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

View file

@ -202,8 +202,11 @@ class PacketReader {
public void shutdown() { public void shutdown() {
// Notify connection listeners of the connection closing if done hasn't already been set. // Notify connection listeners of the connection closing if done hasn't already been set.
if (!done) { if (!done) {
ArrayList listenersCopy;
synchronized (connectionListeners) { 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(); ConnectionListener listener = (ConnectionListener)i.next();
listener.connectionClosed(); listener.connectionClosed();
} }
@ -222,8 +225,11 @@ class PacketReader {
done = true; done = true;
connection.close(); connection.close();
// Notify connection listeners of the error. // Notify connection listeners of the error.
ArrayList listenersCopy;
synchronized (connectionListeners) { 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(); ConnectionListener listener = (ConnectionListener)i.next();
listener.connectionClosedOnError(e); listener.connectionClosedOnError(e);
} }