@@ -164,7 +164,7 @@ private final void ensureIsOpen()
164164 throws AlreadyClosedException
165165 {
166166 if (!isOpen ()) {
167- throw new AlreadyClosedException ("Attempt to use closed connection" , this );
167+ throw new AlreadyClosedException (getCloseReason () );
168168 }
169169 }
170170
@@ -312,14 +312,11 @@ public void start()
312312 response = sm .handleChallenge (challenge , this .username , this .password );
313313 }
314314 } catch (ShutdownSignalException e ) {
315- Object shutdownReason = e .getReason ();
316- if (shutdownReason instanceof AMQCommand ) {
317- Method shutdownMethod = ((AMQCommand ) shutdownReason ).getMethod ();
318- if (shutdownMethod instanceof AMQP .Connection .Close ) {
319- AMQP .Connection .Close shutdownClose = (AMQP .Connection .Close ) shutdownMethod ;
320- if (shutdownClose .getReplyCode () == AMQP .ACCESS_REFUSED ) {
321- throw new AuthenticationFailureException (shutdownClose .getReplyText ());
322- }
315+ Method shutdownMethod = e .getReason ();
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 ());
323320 }
324321 }
325322 throw new PossibleAuthenticationFailureException (e );
@@ -534,11 +531,11 @@ private class MainLoop extends Thread {
534531 }
535532 } catch (EOFException ex ) {
536533 if (!_brokerInitiatedShutdown )
537- shutdown (ex , false , ex , true );
534+ shutdown (null , false , ex , true );
538535 } catch (Throwable ex ) {
539536 _exceptionHandler .handleUnexpectedConnectionDriverException (AMQConnection .this ,
540537 ex );
541- shutdown (ex , false , ex , true );
538+ shutdown (null , false , ex , true );
542539 } finally {
543540 // Finally, shut down our underlying data connection.
544541 _frameHandler .close ();
@@ -631,7 +628,7 @@ public boolean processControlCommand(Command c) throws IOException
631628 }
632629
633630 public void handleConnectionClose (Command closeCommand ) {
634- ShutdownSignalException sse = shutdown (closeCommand , false , null , _inConnectionNegotiation );
631+ ShutdownSignalException sse = shutdown (closeCommand . getMethod () , false , null , _inConnectionNegotiation );
635632 try {
636633 _channel0 .quiescingTransmit (new AMQP .Connection .CloseOk .Builder ().build ());
637634 } catch (IOException _) { } // ignore
@@ -664,13 +661,13 @@ public SocketCloseWait(ShutdownSignalException sse) {
664661 * built from the argument, and stops this connection from accepting further work from the
665662 * application. {@link com.rabbitmq.client.ShutdownListener ShutdownListener}s for the
666663 * connection are notified when the main loop terminates.
667- * @param reason object being shutdown
664+ * @param reason description of reason for the exception
668665 * @param initiatedByApplication true if caused by a client command
669666 * @param cause trigger exception which caused shutdown
670667 * @param notifyRpc true if outstanding rpc should be informed of shutdown
671668 * @return a shutdown signal built using the given arguments
672669 */
673- public ShutdownSignalException shutdown (Object reason ,
670+ public ShutdownSignalException shutdown (Method reason ,
674671 boolean initiatedByApplication ,
675672 Throwable cause ,
676673 boolean notifyRpc )
@@ -680,7 +677,7 @@ public ShutdownSignalException shutdown(Object reason,
680677 return sse ;
681678 }
682679
683- private ShutdownSignalException startShutdown (Object reason ,
680+ private ShutdownSignalException startShutdown (Method reason ,
684681 boolean initiatedByApplication ,
685682 Throwable cause ,
686683 boolean notifyRpc )
@@ -690,7 +687,7 @@ private ShutdownSignalException startShutdown(Object reason,
690687 sse .initCause (cause );
691688 if (!setShutdownCauseIfOpen (sse )) {
692689 if (initiatedByApplication )
693- throw new AlreadyClosedException ("Attempt to use closed connection" , this );
690+ throw new AlreadyClosedException (getCloseReason () );
694691 }
695692
696693 // stop any heartbeating
@@ -813,8 +810,11 @@ public AMQCommand transformReply(AMQCommand command) {
813810 _channel0 .quiescingTransmit (reason );
814811 }
815812 } catch (TimeoutException tte ) {
816- if (!abort )
817- throw new ShutdownSignalException (true , true , tte , this );
813+ if (!abort ) {
814+ ShutdownSignalException sse = new ShutdownSignalException (true , true , null , this );
815+ sse .initCause (cause );
816+ throw sse ;
817+ }
818818 } catch (ShutdownSignalException sse ) {
819819 if (!abort )
820820 throw sse ;
0 commit comments