@@ -300,15 +300,13 @@ public void close(int closeCode, String closeMessage) throws IOException {
300
300
*/
301
301
public void addShutdownListener (ShutdownListener listener ) {
302
302
this .shutdownHooks .add (listener );
303
- delegate .addShutdownListener (listener );
304
303
}
305
304
306
305
/**
307
306
* @see com.rabbitmq.client.ShutdownNotifier#removeShutdownListener(com.rabbitmq.client.ShutdownListener)
308
307
*/
309
308
public void removeShutdownListener (ShutdownListener listener ) {
310
309
this .shutdownHooks .remove (listener );
311
- delegate .removeShutdownListener (listener );
312
310
}
313
311
314
312
/**
@@ -378,6 +376,12 @@ private void addAutomaticRecoveryListener() {
378
376
final AutorecoveringConnection c = this ;
379
377
ShutdownListener automaticRecoveryListener = new ShutdownListener () {
380
378
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
+
381
385
try {
382
386
if (shouldTriggerConnectionRecovery (cause )) {
383
387
c .beginAutomaticRecovery ();
@@ -387,12 +391,7 @@ public void shutdownCompleted(ShutdownSignalException cause) {
387
391
}
388
392
}
389
393
};
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 );
396
395
}
397
396
398
397
protected boolean shouldTriggerConnectionRecovery (ShutdownSignalException cause ) {
@@ -456,9 +455,8 @@ synchronized private void beginAutomaticRecovery() throws InterruptedException,
456
455
}
457
456
458
457
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 ();
462
460
}
463
461
464
462
private void recoverBlockedListeners () {
0 commit comments