3030 * Public API: Interface to an AMQ connection. See the see the <a href="http://www.amqp.org/">spec</a> for details.
3131 * <p>
3232 * To connect to a broker, fill in a {@link ConnectionParameters} and use a {@link ConnectionFactory} as follows:
33- *
33+ *
3434 * <pre>
3535 * ConnectionParameters params = new ConnectionParameters();
3636 * params.setUsername(userName);
4141 * Connection conn = factory.newConnection(hostName, AMQP.PROTOCOL.PORT);
4242 *
4343 * // Then open a channel and retrieve an access ticket:
44- *
44+ *
4545 * Channel channel = conn.createChannel();
4646 * int ticket = channel.accessRequest(realmName);
4747 * </pre>
4848 *
4949 * Current implementations are thread-safe for code at the client API level,
5050 * and in fact thread-safe internally except for code within RPC calls.
5151 */
52- public interface Connection { // rename to AMQPConnection later, this is a temporary name
52+ public interface Connection extends ShutdownNotifier { // rename to AMQPConnection later, this is a temporary name
5353 /**
5454 * Retrieve the host.
5555 * @return the hostname of the peer we're connected to.
@@ -104,7 +104,7 @@ public interface Connection { // rename to AMQPConnection later, this is a tempo
104104 * @return an array of addresses for all hosts that came back in the initial {@link com.rabbitmq.client.AMQP.Connection.OpenOk} open-ok method
105105 */
106106 Address [] getKnownHosts ();
107-
107+
108108 /**
109109 * Create a new channel, using an internally allocated channel number.
110110 * @return a new channel descriptor, or null if none is available
@@ -119,12 +119,46 @@ public interface Connection { // rename to AMQPConnection later, this is a tempo
119119 * @throws IOException if an I/O problem is encountered
120120 */
121121 Channel createChannel (int channelNumber ) throws IOException ;
122-
122+
123+ /**
124+ * Close this connection and all its channels.
125+ *
126+ * This method will wait infinitely for all the close operations to
127+ * complete.
128+ *
129+ * @throws IOException if an I/O problem is encountered
130+ */
131+ void close () throws IOException ;
132+
123133 /**
124- * Close this connection with the given code and message.
125- * @param closeCode code indicating the reason for closing the connection - see AMQP spec for a list of codes
126- * @param closeMessage optional message describing the reason for closing the connection
134+ * Close this connection and all its channels
135+ *
136+ * This method will wait with the given timeout for all the close
137+ * operations to complete. If timeout is reached then socket is forced
138+ * to close
139+ * @param timeout timeout (in milioseconds) for completing all the close-related
140+ * operations, use -1 for infinity
127141 * @throws IOException if an I/O problem is encountered
128142 */
129- void close (int closeCode , String closeMessage ) throws IOException ;
143+ void close (int timeout ) throws IOException ;
144+
145+ /**
146+ * Abort this connection and all its channels.
147+ *
148+ * This method will force the connection to close. It will silently discard
149+ * any exceptions enountered in close operations
150+ */
151+ void abort ();
152+
153+ /**
154+ * Abort this connection and all its channels.
155+ *
156+ * This method behaves in a similar way as abort(), with the only difference
157+ * that it will wait with a provided timeout for all the close operations to
158+ * complete. If timeout is reached socket is forced to close.
159+ *
160+ * @param timeout timeout (in miliseconds) for completing all the close-related
161+ * operations, use -1 for infinity
162+ */
163+ void abort (int timeout );
130164}
0 commit comments