@@ -300,15 +300,13 @@ public void close(int closeCode, String closeMessage) throws IOException {
300300 */
301301 public void addShutdownListener (ShutdownListener listener ) {
302302 this .shutdownHooks .add (listener );
303- delegate .addShutdownListener (listener );
304303 }
305304
306305 /**
307306 * @see com.rabbitmq.client.ShutdownNotifier#removeShutdownListener(com.rabbitmq.client.ShutdownListener)
308307 */
309308 public void removeShutdownListener (ShutdownListener listener ) {
310309 this .shutdownHooks .remove (listener );
311- delegate .removeShutdownListener (listener );
312310 }
313311
314312 /**
@@ -378,6 +376,12 @@ private void addAutomaticRecoveryListener() {
378376 final AutorecoveringConnection c = this ;
379377 ShutdownListener automaticRecoveryListener = new ShutdownListener () {
380378 public void shutdownCompleted (ShutdownSignalException cause ) {
379+
380+ //Call each shutdown listener before reconnecting.
381+ for (ShutdownListener listener : c .shutdownHooks ) {
382+ listener .shutdownCompleted (cause );
383+ }
384+
381385 try {
382386 if (shouldTriggerConnectionRecovery (cause )) {
383387 c .beginAutomaticRecovery ();
@@ -387,12 +391,7 @@ public void shutdownCompleted(ShutdownSignalException cause) {
387391 }
388392 }
389393 };
390- synchronized (this ) {
391- if (!this .shutdownHooks .contains (automaticRecoveryListener )) {
392- this .shutdownHooks .add (automaticRecoveryListener );
393- }
394- this .delegate .addShutdownListener (automaticRecoveryListener );
395- }
394+ this .delegate .addShutdownListener (automaticRecoveryListener );
396395 }
397396
398397 protected boolean shouldTriggerConnectionRecovery (ShutdownSignalException cause ) {
@@ -456,9 +455,8 @@ synchronized private void beginAutomaticRecovery() throws InterruptedException,
456455 }
457456
458457 private void recoverShutdownListeners () {
459- for (ShutdownListener sh : this .shutdownHooks ) {
460- this .delegate .addShutdownListener (sh );
461- }
458+ //Add the auto recovering listener to the new delegate.
459+ addAutomaticRecoveryListener ();
462460 }
463461
464462 private void recoverBlockedListeners () {
0 commit comments