2727import java .io .EOFException ;
2828import java .io .IOException ;
2929import java .net .SocketException ;
30- import java .util .Collections ;
31- import java .util .LinkedList ;
32- import java .util .List ;
3330import java .util .Map ;
3431import java .util .concurrent .TimeoutException ;
3532
36- import java .io .EOFException ;
37- import java .io .IOException ;
38- import java .net .SocketException ;
39- import java .util .Map ;
40-
4133import com .rabbitmq .client .AMQP ;
4234import com .rabbitmq .client .Address ;
4335import com .rabbitmq .client .AlreadyClosedException ;
4739import com .rabbitmq .client .ConnectionParameters ;
4840import com .rabbitmq .client .MissedHeartbeatException ;
4941import com .rabbitmq .client .RedirectException ;
50- import com .rabbitmq .client .ShutdownListener ;
5142import com .rabbitmq .client .ShutdownSignalException ;
5243import com .rabbitmq .utility .BlockingCell ;
5344import com .rabbitmq .utility .Utility ;
7061 * int ticket = ch1.accessRequest(realmName);
7162 * </pre>
7263 */
73- public class AMQConnection implements Connection {
64+ public class AMQConnection extends ShutdownNotifierComponent implements Connection {
7465 /** Timeout used while waiting for AMQP handshaking to complete (milliseconds) */
7566 public static final int HANDSHAKE_TIMEOUT = 10000 ;
76-
67+
7768 /** Timeout used while waiting for a connection.close-ok (milliseconds) */
7869 public static final int CONNECTION_CLOSING_TIMEOUT = 10000 ;
79-
8070
8171 private static final Version clientVersion =
8272 new Version (AMQP .PROTOCOL .MAJOR , AMQP .PROTOCOL .MINOR );
@@ -100,23 +90,12 @@ public class AMQConnection implements Connection {
10090 /** Flag controlling the main driver loop's termination */
10191 public volatile boolean _running = false ;
10292
103- /**
104- * When this value is null, the connection is in an "open"
105- * state. When non-null, the connection is in "closed" state, and
106- * this value indicates the circumstances of the shutdown.
107- */
108- public volatile ShutdownSignalException _shutdownCause = null ;
109-
11093 /** Maximum frame length, or zero if no limit is set */
11194 public int _frameMax ;
11295
11396 /** Handler for (otherwise-unhandled) exceptions that crop up in the mainloop. */
11497 public final ExceptionHandler _exceptionHandler ;
11598
116- /** List of all shutdown listeners associated with the connection */
117- public List <ShutdownListener > listeners
118- = Collections .synchronizedList (new LinkedList <ShutdownListener >());
119-
12099 public BlockingCell <Object > appContinuation = new BlockingCell <Object >();
121100
122101 /**
@@ -127,14 +106,6 @@ public final void disconnectChannel(int channelNumber) {
127106 _channelManager .disconnectChannel (channelNumber );
128107 }
129108
130- /**
131- * Public API - Determine whether the connection is open
132- * @return true if haven't yet received shutdown signal, false otherwise
133- */
134- public boolean isOpen () {
135- return _shutdownCause == null ;
136- }
137-
138109 public void ensureIsOpen ()
139110 throws AlreadyClosedException
140111 {
@@ -492,7 +463,7 @@ public MainLoop() {
492463 shutdown (ex , false , ex );
493464 }
494465 }
495-
466+
496467 // Finally, shut down our underlying data connection.
497468 _frameHandler .close ();
498469
@@ -724,55 +695,6 @@ public void close(int closeCode,
724695 }
725696 notifyListeners ();
726697 }
727-
728- /**
729- * Private API - notify the listeners attached to this connection
730- * @see com.rabbitmq.client.ShutdownListener
731- */
732- public void notifyListeners ()
733- {
734- synchronized (listeners ) {
735- for (ShutdownListener l : listeners )
736- l .service (getCloseReason ());
737- }
738- }
739-
740- /**
741- * Public API - Add shutdown listener fired when closing the connection
742- * @see com.rabbitmq.client.Connection#addShutdownListener()
743- */
744- public void addShutdownListener (ShutdownListener listener )
745- {
746-
747- boolean closed = false ;
748- synchronized (listeners ) {
749- closed = !isOpen ();
750- listeners .add (listener );
751- }
752- if (closed )
753- listener .service (_shutdownCause );
754- }
755-
756- /**
757- * Public API - Remove shutdown listener for this connection
758- * Removing only the first found object
759- * @see com.rabbitmq.client.Connection#removeShutdownListener()
760- */
761- public void removeShutdownListener (ShutdownListener listener )
762- {
763- synchronized (listeners ) {
764- listeners .remove (listener );
765- }
766- }
767-
768- /**
769- * Public API - Get reason for shutdown, or null if open
770- * @see com.rabbitmq.client.Connection#getShutdownReason()
771- */
772- public ShutdownSignalException getCloseReason ()
773- {
774- return _shutdownCause ;
775- }
776698
777699 @ Override public String toString () {
778700 return "amqp://" + _params .getUserName () + "@" + getHost () + ":" + getPort () + _params .getVirtualHost ();
0 commit comments