@@ -163,7 +163,7 @@ private final void ensureIsOpen()
163163 throws AlreadyClosedException
164164 {
165165 if (!isOpen ()) {
166- throw new AlreadyClosedException ("Attempt to use closed connection" , this );
166+ throw new AlreadyClosedException (getCloseReason () );
167167 }
168168 }
169169
@@ -310,14 +310,11 @@ public void start()
310310 response = sm .handleChallenge (challenge , this .username , this .password );
311311 }
312312 } catch (ShutdownSignalException e ) {
313- Object shutdownReason = e .getReason ();
314- if (shutdownReason instanceof AMQCommand ) {
315- Method shutdownMethod = ((AMQCommand ) shutdownReason ).getMethod ();
316- if (shutdownMethod instanceof AMQP .Connection .Close ) {
317- AMQP .Connection .Close shutdownClose = (AMQP .Connection .Close ) shutdownMethod ;
318- if (shutdownClose .getReplyCode () == AMQP .ACCESS_REFUSED ) {
319- throw new AuthenticationFailureException (shutdownClose .getReplyText ());
320- }
313+ Method shutdownMethod = e .getReason ();
314+ if (shutdownMethod instanceof AMQP .Connection .Close ) {
315+ AMQP .Connection .Close shutdownClose = (AMQP .Connection .Close ) shutdownMethod ;
316+ if (shutdownClose .getReplyCode () == AMQP .ACCESS_REFUSED ) {
317+ throw new AuthenticationFailureException (shutdownClose .getReplyText ());
321318 }
322319 }
323320 throw new PossibleAuthenticationFailureException (e );
@@ -532,11 +529,11 @@ private class MainLoop extends Thread {
532529 }
533530 } catch (EOFException ex ) {
534531 if (!_brokerInitiatedShutdown )
535- shutdown (ex , false , ex , true );
532+ shutdown (null , false , ex , true );
536533 } catch (Throwable ex ) {
537534 _exceptionHandler .handleUnexpectedConnectionDriverException (AMQConnection .this ,
538535 ex );
539- shutdown (ex , false , ex , true );
536+ shutdown (null , false , ex , true );
540537 } finally {
541538 // Finally, shut down our underlying data connection.
542539 _frameHandler .close ();
@@ -629,7 +626,7 @@ public boolean processControlCommand(Command c) throws IOException
629626 }
630627
631628 public void handleConnectionClose (Command closeCommand ) {
632- ShutdownSignalException sse = shutdown (closeCommand , false , null , _inConnectionNegotiation );
629+ ShutdownSignalException sse = shutdown (closeCommand . getMethod () , false , null , _inConnectionNegotiation );
633630 try {
634631 _channel0 .quiescingTransmit (new AMQP .Connection .CloseOk .Builder ().build ());
635632 } catch (IOException _) { } // ignore
@@ -662,13 +659,13 @@ public SocketCloseWait(ShutdownSignalException sse) {
662659 * built from the argument, and stops this connection from accepting further work from the
663660 * application. {@link com.rabbitmq.client.ShutdownListener ShutdownListener}s for the
664661 * connection are notified when the main loop terminates.
665- * @param reason object being shutdown
662+ * @param reason description of reason for the exception
666663 * @param initiatedByApplication true if caused by a client command
667664 * @param cause trigger exception which caused shutdown
668665 * @param notifyRpc true if outstanding rpc should be informed of shutdown
669666 * @return a shutdown signal built using the given arguments
670667 */
671- public ShutdownSignalException shutdown (Object reason ,
668+ public ShutdownSignalException shutdown (Method reason ,
672669 boolean initiatedByApplication ,
673670 Throwable cause ,
674671 boolean notifyRpc )
@@ -678,7 +675,7 @@ public ShutdownSignalException shutdown(Object reason,
678675 return sse ;
679676 }
680677
681- private ShutdownSignalException startShutdown (Object reason ,
678+ private ShutdownSignalException startShutdown (Method reason ,
682679 boolean initiatedByApplication ,
683680 Throwable cause ,
684681 boolean notifyRpc )
@@ -688,7 +685,7 @@ private ShutdownSignalException startShutdown(Object reason,
688685 sse .initCause (cause );
689686 if (!setShutdownCauseIfOpen (sse )) {
690687 if (initiatedByApplication )
691- throw new AlreadyClosedException ("Attempt to use closed connection" , this );
688+ throw new AlreadyClosedException (getCloseReason () );
692689 }
693690
694691 // stop any heartbeating
@@ -811,8 +808,11 @@ public AMQCommand transformReply(AMQCommand command) {
811808 _channel0 .quiescingTransmit (reason );
812809 }
813810 } catch (TimeoutException tte ) {
814- if (!abort )
815- throw new ShutdownSignalException (true , true , tte , this );
811+ if (!abort ) {
812+ ShutdownSignalException sse = new ShutdownSignalException (true , true , null , this );
813+ sse .initCause (cause );
814+ throw sse ;
815+ }
816816 } catch (ShutdownSignalException sse ) {
817817 if (!abort )
818818 throw sse ;
0 commit comments