@@ -170,7 +170,7 @@ private final void ensureIsOpen()
170170 throws AlreadyClosedException
171171 {
172172 if (!isOpen ()) {
173- throw new AlreadyClosedException ("Attempt to use closed connection" , this );
173+ throw new AlreadyClosedException (getCloseReason () );
174174 }
175175 }
176176
@@ -331,14 +331,11 @@ public void start()
331331 response = sm .handleChallenge (challenge , this .username , this .password );
332332 }
333333 } catch (ShutdownSignalException e ) {
334- Object shutdownReason = e .getReason ();
335- if (shutdownReason instanceof AMQCommand ) {
336- Method shutdownMethod = ((AMQCommand ) shutdownReason ).getMethod ();
337- if (shutdownMethod instanceof AMQP .Connection .Close ) {
338- AMQP .Connection .Close shutdownClose = (AMQP .Connection .Close ) shutdownMethod ;
339- if (shutdownClose .getReplyCode () == AMQP .ACCESS_REFUSED ) {
340- throw new AuthenticationFailureException (shutdownClose .getReplyText ());
341- }
334+ Method shutdownMethod = e .getReason ();
335+ if (shutdownMethod instanceof AMQP .Connection .Close ) {
336+ AMQP .Connection .Close shutdownClose = (AMQP .Connection .Close ) shutdownMethod ;
337+ if (shutdownClose .getReplyCode () == AMQP .ACCESS_REFUSED ) {
338+ throw new AuthenticationFailureException (shutdownClose .getReplyText ());
342339 }
343340 }
344341 throw new PossibleAuthenticationFailureException (e );
@@ -563,11 +560,11 @@ private class MainLoop implements Runnable {
563560 }
564561 } catch (EOFException ex ) {
565562 if (!_brokerInitiatedShutdown )
566- shutdown (ex , false , ex , true );
563+ shutdown (null , false , ex , true );
567564 } catch (Throwable ex ) {
568565 _exceptionHandler .handleUnexpectedConnectionDriverException (AMQConnection .this ,
569566 ex );
570- shutdown (ex , false , ex , true );
567+ shutdown (null , false , ex , true );
571568 } finally {
572569 // Finally, shut down our underlying data connection.
573570 _frameHandler .close ();
@@ -660,7 +657,7 @@ public boolean processControlCommand(Command c) throws IOException
660657 }
661658
662659 public void handleConnectionClose (Command closeCommand ) {
663- ShutdownSignalException sse = shutdown (closeCommand , false , null , _inConnectionNegotiation );
660+ ShutdownSignalException sse = shutdown (closeCommand . getMethod () , false , null , _inConnectionNegotiation );
664661 try {
665662 _channel0 .quiescingTransmit (new AMQP .Connection .CloseOk .Builder ().build ());
666663 } catch (IOException _) { } // ignore
@@ -694,13 +691,13 @@ public SocketCloseWait(ShutdownSignalException sse) {
694691 * built from the argument, and stops this connection from accepting further work from the
695692 * application. {@link com.rabbitmq.client.ShutdownListener ShutdownListener}s for the
696693 * connection are notified when the main loop terminates.
697- * @param reason object being shutdown
694+ * @param reason description of reason for the exception
698695 * @param initiatedByApplication true if caused by a client command
699696 * @param cause trigger exception which caused shutdown
700697 * @param notifyRpc true if outstanding rpc should be informed of shutdown
701698 * @return a shutdown signal built using the given arguments
702699 */
703- public ShutdownSignalException shutdown (Object reason ,
700+ public ShutdownSignalException shutdown (Method reason ,
704701 boolean initiatedByApplication ,
705702 Throwable cause ,
706703 boolean notifyRpc )
@@ -710,7 +707,7 @@ public ShutdownSignalException shutdown(Object reason,
710707 return sse ;
711708 }
712709
713- private ShutdownSignalException startShutdown (Object reason ,
710+ private ShutdownSignalException startShutdown (Method reason ,
714711 boolean initiatedByApplication ,
715712 Throwable cause ,
716713 boolean notifyRpc )
@@ -720,7 +717,7 @@ private ShutdownSignalException startShutdown(Object reason,
720717 sse .initCause (cause );
721718 if (!setShutdownCauseIfOpen (sse )) {
722719 if (initiatedByApplication )
723- throw new AlreadyClosedException ("Attempt to use closed connection" , this );
720+ throw new AlreadyClosedException (getCloseReason () );
724721 }
725722
726723 // stop any heartbeating
@@ -843,8 +840,11 @@ public AMQCommand transformReply(AMQCommand command) {
843840 _channel0 .quiescingTransmit (reason );
844841 }
845842 } catch (TimeoutException tte ) {
846- if (!abort )
847- throw new ShutdownSignalException (true , true , tte , this );
843+ if (!abort ) {
844+ ShutdownSignalException sse = new ShutdownSignalException (true , true , null , this );
845+ sse .initCause (cause );
846+ throw sse ;
847+ }
848848 } catch (ShutdownSignalException sse ) {
849849 if (!abort )
850850 throw sse ;
0 commit comments