From 2db477145d6db49b24d114fec46b705d25c7913c Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Thu, 8 Feb 2007 18:23:44 +0000 Subject: [PATCH] 1) Use #notifyAll to notify all waiting threads on listenethread. SMACK-189 2) Added try/catch while notifying listener to recover gracefully from potential errors. SMACK-190 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7043 b35dd754-fafc-0310-a699-88a17e54d16e --- .../org/jivesoftware/smack/PacketReader.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/source/org/jivesoftware/smack/PacketReader.java b/source/org/jivesoftware/smack/PacketReader.java index 1a6fbdd8f..9e960d719 100644 --- a/source/org/jivesoftware/smack/PacketReader.java +++ b/source/org/jivesoftware/smack/PacketReader.java @@ -185,7 +185,14 @@ class PacketReader { // Make a copy since it's possible that a listener will be removed from the list listenersCopy = new ArrayList(connectionListeners); for (ConnectionListener listener : listenersCopy) { - listener.connectionClosed(); + try { + listener.connectionClosed(); + } + catch (Exception e) { + // Cath and print any exception so we can recover + // from a faulty listener and finish the shutdown process + e.printStackTrace(); + } } } } @@ -193,7 +200,7 @@ class PacketReader { // Make sure that the listenerThread is awake to shutdown properly synchronized (listenerThread) { - listenerThread.notify(); + listenerThread.notifyAll(); } } @@ -215,13 +222,20 @@ class PacketReader { // Make a copy since it's possible that a listener will be removed from the list listenersCopy = new ArrayList(connectionListeners); for (ConnectionListener listener : listenersCopy) { - listener.connectionClosedOnError(e); + try { + listener.connectionClosedOnError(e); + } + catch (Exception e2) { + // Cath and print any exception so we can recover + // from a faulty listener + e2.printStackTrace(); + } } } // Make sure that the listenerThread is awake to shutdown properly synchronized (listenerThread) { - listenerThread.notify(); + listenerThread.notifyAll(); } } @@ -235,13 +249,20 @@ class PacketReader { // Make a copy since it's possible that a listener will be removed from the list listenersCopy = new ArrayList(connectionListeners); for (ConnectionListener listener : listenersCopy) { - listener.reconnectionSuccessful(); + try { + listener.reconnectionSuccessful(); + } + catch (Exception e) { + // Cath and print any exception so we can recover + // from a faulty listener + e.printStackTrace(); + } } } // Make sure that the listenerThread is awake to shutdown properly synchronized (listenerThread) { - listenerThread.notify(); + listenerThread.notifyAll(); } }