3030import com .rabbitmq .client .AlreadyClosedException ;
3131import com .rabbitmq .client .Command ;
3232import com .rabbitmq .client .Connection ;
33- import com .rabbitmq .client .ShutdownListener ;
3433import com .rabbitmq .client .ShutdownSignalException ;
3534import com .rabbitmq .utility .BlockingValueOrException ;
3635import com .rabbitmq .utility .SingleShotLinearTimer ;
4342 * @see ChannelN
4443 * @see Connection
4544 */
46- public abstract class AMQChannel {
45+ public abstract class AMQChannel extends ShutdownNotifierComponent {
4746 /** The connection this channel is associated with. */
4847 public final AMQConnection _connection ;
4948
@@ -55,9 +54,6 @@ public abstract class AMQChannel {
5554
5655 /** The current outstanding RPC request, if any. (Could become a queue in future.) */
5756 public RpcContinuation _activeRpc = null ;
58-
59- /** Reason for closing the channel, null if still open */
60- public volatile ShutdownSignalException _cause ;
6157
6258 /**
6359 * Construct a channel on the given connection, with the given channel number.
@@ -119,6 +115,10 @@ public AMQCommand exnWrappingRpc(Method m)
119115 {
120116 try {
121117 return rpc (m );
118+ } catch (AlreadyClosedException ace ) {
119+ // Do not wrap it since it means that connection/channel
120+ // was closed in some action in the past
121+ throw ace ;
122122 } catch (ShutdownSignalException ex ) {
123123 throw wrap (ex );
124124 }
@@ -169,29 +169,11 @@ public synchronized RpcContinuation nextOutstandingRpc()
169169 return result ;
170170 }
171171
172- /**
173- * Public API - Indicates whether this channel is in an open state
174- * @return true if channel is open, false otherwise
175- */
176- public boolean isOpen ()
177- {
178- return _cause == null ;
179- }
180-
181- /**
182- * Public API - Get the reason for closing the channel
183- * @return object having information about the shutdown, or null if still open
184- */
185- public ShutdownSignalException getCloseReason ()
186- {
187- return _cause ;
188- }
189-
190172 public void ensureIsOpen ()
191173 throws AlreadyClosedException
192174 {
193175 if (!isOpen ()) {
194- throw new AlreadyClosedException ("Attempt to use closed channel" );
176+ throw new AlreadyClosedException ("Attempt to use closed channel" , this );
195177 }
196178 }
197179
@@ -278,7 +260,7 @@ public void run() {
278260 public void processShutdownSignal (ShutdownSignalException signal ) {
279261 synchronized (this ) {
280262 ensureIsOpen (); // invariant: we should never be shut down more than once per instance
281- _cause = signal ;
263+ _shutdownCause = signal ;
282264 }
283265 RpcContinuation k = nextOutstandingRpc ();
284266 if (k != null ) {
0 commit comments