2828import java .io .EOFException ;
2929import java .io .IOException ;
3030import java .net .SocketException ;
31- import java .util .ArrayList ;
32- import java .util .List ;
3331import java .util .Map ;
3432
3533import com .rabbitmq .client .AMQP ;
4139import com .rabbitmq .client .ConnectionParameters ;
4240import com .rabbitmq .client .MissedHeartbeatException ;
4341import com .rabbitmq .client .RedirectException ;
44- import com .rabbitmq .client .ShutdownListener ;
4542import com .rabbitmq .client .ShutdownSignalException ;
4643import com .rabbitmq .utility .Utility ;
4744
6360 * int ticket = ch1.accessRequest(realmName);
6461 * </pre>
6562 */
66- public class AMQConnection implements Connection {
63+ public class AMQConnection extends ShutdownNotifierComponent implements Connection {
6764 /** Timeout used while waiting for AMQP handshaking to complete (milliseconds) */
6865 public static final int HANDSHAKE_TIMEOUT = 10000 ;
6966
@@ -92,23 +89,12 @@ public class AMQConnection implements Connection {
9289 /** Flag controlling the main driver loop's termination */
9390 public volatile boolean _running = false ;
9491
95- /**
96- * When this value is null, the connection is in an "open"
97- * state. When non-null, the connection is in "closed" state, and
98- * this value indicates the circumstances of the shutdown.
99- */
100- public volatile ShutdownSignalException _shutdownCause = null ;
101-
10292 /** Maximum frame length, or zero if no limit is set */
10393 public int _frameMax ;
10494
10595 /** Handler for (otherwise-unhandled) exceptions that crop up in the mainloop. */
10696 public final ExceptionHandler _exceptionHandler ;
10797
108- /** List of all shutdown listeners associated with the connection */
109- public List <ShutdownListener > listeners
110- = new ArrayList <ShutdownListener >();
111-
11298 /**
11399 * Protected API - respond, in the driver thread, to a ShutdownSignal.
114100 * @param channelNumber the number of the channel to disconnect
@@ -117,14 +103,6 @@ public final void disconnectChannel(int channelNumber) {
117103 _channelManager .disconnectChannel (channelNumber );
118104 }
119105
120- /**
121- * Public API - Determine whether the connection is open
122- * @return true if haven't yet received shutdown signal, false otherwise
123- */
124- public boolean isOpen () {
125- return _shutdownCause == null ;
126- }
127-
128106 public void ensureIsOpen ()
129107 throws AlreadyClosedException
130108 {
@@ -629,55 +607,6 @@ public void close(int closeCode,
629607 }
630608 notifyListeners ();
631609 }
632-
633- /**
634- * Private API - notify the listeners attached to this connection
635- * @see com.rabbitmq.client.ShutdownListener
636- */
637- public void notifyListeners ()
638- {
639- synchronized (listeners ) {
640- for (ShutdownListener l : listeners )
641- l .service (getCloseReason ());
642- }
643- }
644-
645- /**
646- * Public API - Add shutdown listener fired when closing the connection
647- * @see com.rabbitmq.client.Connection#addShutdownListener()
648- */
649- public void addShutdownListener (ShutdownListener listener )
650- {
651-
652- boolean closed = false ;
653- synchronized (listeners ) {
654- closed = !isOpen ();
655- listeners .add (listener );
656- }
657- if (closed )
658- listener .service (_shutdownCause );
659- }
660-
661- /**
662- * Public API - Remove shutdown listener for this connection
663- * Removing only the first found object
664- * @see com.rabbitmq.client.Connection#removeShutdownListener()
665- */
666- public void removeShutdownListener (ShutdownListener listener )
667- {
668- synchronized (listeners ) {
669- listeners .remove (listener );
670- }
671- }
672-
673- /**
674- * Public API - Get reason for shutdown, or null if open
675- * @see com.rabbitmq.client.Connection#getShutdownReason()
676- */
677- public ShutdownSignalException getCloseReason ()
678- {
679- return _shutdownCause ;
680- }
681610
682611 @ Override public String toString () {
683612 return "amqp://" + _params .getUserName () + "@" + getHost () + ":" + getPort () + _params .getVirtualHost ();
0 commit comments