@@ -239,6 +239,7 @@ public void setDefaultConsumer(Consumer consumer) {
239239
240240 /**
241241 * Sends a ShutdownSignal to all active consumers.
242+ * Idempotent.
242243 * @param signal an exception signalling channel shutdown
243244 */
244245 private void broadcastShutdownSignal (ShutdownSignalException signal ) {
@@ -250,19 +251,39 @@ private void broadcastShutdownSignal(ShutdownSignalException signal) {
250251 }
251252
252253 /**
253- * Protected API - overridden to quiesce consumer work and broadcast the signal
254- * to all consumers after calling the superclass's method.
254+ * Start to shutdown -- defer rest of processing until ready
255255 */
256- @ Override public void processShutdownSignal (ShutdownSignalException signal ,
256+ private void startProcessShutdownSignal (ShutdownSignalException signal ,
257257 boolean ignoreClosed ,
258258 boolean notifyRpc )
259+ { super .processShutdownSignal (signal , ignoreClosed , notifyRpc );
260+ }
261+
262+ /**
263+ * Finish shutdown processing -- idempotent
264+ */
265+ private void finishProcessShutdownSignal ()
259266 {
260- super .processShutdownSignal (signal , ignoreClosed , notifyRpc );
267+ this .dispatcher .quiesce ();
268+ broadcastShutdownSignal (getCloseReason ());
269+
261270 synchronized (unconfirmedSet ) {
262271 unconfirmedSet .notifyAll ();
263272 }
264273 }
265274
275+ /**
276+ * Protected API - overridden to quiesce consumer work and broadcast the signal
277+ * to all consumers after calling the superclass's method.
278+ */
279+ @ Override public void processShutdownSignal (ShutdownSignalException signal ,
280+ boolean ignoreClosed ,
281+ boolean notifyRpc )
282+ {
283+ startProcessShutdownSignal (signal , ignoreClosed , notifyRpc );
284+ finishProcessShutdownSignal ();
285+ }
286+
266287 CountDownLatch getShutdownLatch () {
267288 return this .finishedShutdownFlag ;
268289 }
@@ -527,17 +548,15 @@ public void close(int closeCode,
527548 BlockingRpcContinuation <AMQCommand > k = new BlockingRpcContinuation <AMQCommand >(){
528549 @ Override
529550 public AMQCommand transformReply (AMQCommand command ) {
530- ChannelN .this .dispatcher .quiesce ();
531- broadcastShutdownSignal (getCloseReason ());
532-
551+ ChannelN .this .finishProcessShutdownSignal ();
533552 return command ;
534553 }};
535554 boolean notify = false ;
536555 try {
537556 // Synchronize the block below to avoid race conditions in case
538557 // connnection wants to send Connection-CloseOK
539558 synchronized (_channelMutex ) {
540- processShutdownSignal (signal , !initiatedByApplication , true );
559+ startProcessShutdownSignal (signal , !initiatedByApplication , true );
541560 quiescingRpc (reason , k );
542561 }
543562
0 commit comments