Skip to content

Commit 74ca20d

Browse files
author
Matthias Radestock
committed
merge bug19470 into default
2 parents 5e3c3fb + 803dd48 commit 74ca20d

File tree

14 files changed

+145
-79
lines changed

14 files changed

+145
-79
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,18 @@ public interface Channel extends ShutdownNotifier{
7070
Connection getConnection();
7171

7272
/**
73-
* Close this channel with the given code and message
73+
* Close this channel with the {@link com.rabbitmq.client.AMQP#REPLY_SUCCESS} close code
74+
* and message 'OK'.
75+
*
76+
* @throws java.io.IOException if an error is encountered
77+
*/
78+
void close() throws IOException;
79+
80+
/**
81+
* Close this channel.
82+
*
7483
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
75-
* @param closeMessage a message indicating the reason for closing the channel
84+
* @param closeMessage a message indicating the reason for closing the connection
7685
* @throws java.io.IOException if an error is encountered
7786
*/
7887
void close(int closeCode, String closeMessage) throws IOException;

src/com/rabbitmq/client/Connection.java

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,44 +121,103 @@ public interface Connection extends ShutdownNotifier { // rename to AMQPConnecti
121121
Channel createChannel(int channelNumber) throws IOException;
122122

123123
/**
124-
* Close this connection and all its channels.
124+
* Close this connection and all its channels
125+
* with the {@link com.rabbitmq.client.AMQP#REPLY_SUCCESS} close code
126+
* and message 'OK'.
125127
*
126-
* This method will wait infinitely for all the close operations to
127-
* complete.
128+
* Waits for all the close operations to complete.
128129
*
129130
* @throws IOException if an I/O problem is encountered
130131
*/
131132
void close() throws IOException;
133+
134+
/**
135+
* Close this connection and all its channels.
136+
*
137+
* Waits for all the close operations to complete.
138+
*
139+
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
140+
* @param closeMessage a message indicating the reason for closing the connection
141+
* @throws IOException if an I/O problem is encountered
142+
*/
143+
void close(int closeCode, String closeMessage) throws IOException;
132144

133145
/**
134146
* 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
147+
* with the {@link com.rabbitmq.client.AMQP#REPLY_SUCCESS} close code
148+
* and message 'OK'.
149+
*
150+
* This method behaves in a similar way as {@link #close()}, with the only difference
151+
* that it waits with a provided timeout for all the close operations to
152+
* complete. When timeout is reached the socket is forced to close.
153+
*
154+
* @param timeout timeout (in milliseconds) for completing all the close-related
140155
* operations, use -1 for infinity
141156
* @throws IOException if an I/O problem is encountered
142157
*/
143158
void close(int timeout) throws IOException;
159+
160+
/**
161+
* Close this connection and all its channels.
162+
*
163+
* Waits with the given timeout for all the close operations to complete.
164+
* When timeout is reached the socket is forced to close.
165+
*
166+
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
167+
* @param closeMessage a message indicating the reason for closing the connection
168+
* @param timeout timeout (in milliseconds) for completing all the close-related
169+
* operations, use -1 for infinity
170+
* @throws IOException if an I/O problem is encountered
171+
*/
172+
void close(int closeCode, String closeMessage, int timeout) throws IOException;
144173

145174
/**
146-
* Abort this connection and all its channels.
175+
* Abort this connection and all its channels
176+
* with the {@link com.rabbitmq.client.AMQP#REPLY_SUCCESS} close code
177+
* and message 'OK'.
147178
*
148-
* This method will force the connection to close. It will silently discard
149-
* any exceptions enountered in close operations
179+
* Forces the connection to close.
180+
* Any encountered exceptions in the close operations are silently discarded.
150181
*/
151182
void abort();
152-
183+
153184
/**
154185
* Abort this connection and all its channels.
155186
*
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.
187+
* Forces the connection to close and waits for all the close operations to complete.
188+
* Any encountered exceptions in the close operations are silently discarded.
189+
*
190+
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
191+
* @param closeMessage a message indicating the reason for closing the connection
192+
*/
193+
void abort(int closeCode, String closeMessage);
194+
195+
/**
196+
* Abort this connection and all its channels
197+
* with the {@link com.rabbitmq.client.AMQP#REPLY_SUCCESS} close code
198+
* and message 'OK'.
199+
*
200+
* This method behaves in a similar way as {@link #abort()}, with the only difference
201+
* that it waits with a provided timeout for all the close operations to
202+
* complete. When timeout is reached the socket is forced to close.
159203
*
160-
* @param timeout timeout (in miliseconds) for completing all the close-related
204+
* @param timeout timeout (in milliseconds) for completing all the close-related
161205
* operations, use -1 for infinity
162206
*/
163207
void abort(int timeout);
208+
209+
/**
210+
* Abort this connection and all its channels.
211+
*
212+
* Forces the connection to close and waits with the given timeout
213+
* for all the close operations to complete. When timeout is reached
214+
* the socket is forced to close.
215+
* Any encountered exceptions in the close operations are silently discarded.
216+
*
217+
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
218+
* @param closeMessage a message indicating the reason for closing the connection
219+
* @param timeout timeout (in milliseconds) for completing all the close-related
220+
* operations, use -1 for infinity
221+
*/
222+
void abort(int closeCode, String closeMessage, int timeout);
164223
}

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
* int ticket = ch1.accessRequest(realmName);
6363
* </pre>
6464
*/
65-
public class AMQConnection extends ShutdownNotifierComponent implements Connection{
65+
public class AMQConnection extends ShutdownNotifierComponent implements Connection {
6666
/** Timeout used while waiting for AMQP handshaking to complete (milliseconds) */
6767
public static final int HANDSHAKE_TIMEOUT = 10000;
6868

@@ -617,59 +617,54 @@ public void shutdown(Object reason,
617617
_channelManager.handleSignal(_shutdownCause);
618618
}
619619

620-
/**
621-
* Public API - Close this connection and all its channels
622-
*/
623620
public void close()
624621
throws IOException
625622
{
626623
close(-1);
627624
}
628625

629-
/**
630-
* Public API - Close this connection and all its channels
631-
* with a given timeout
632-
*/
633626
public void close(int timeout)
634627
throws IOException
635628
{
636-
close(200, "Goodbye", timeout);
629+
close(AMQP.REPLY_SUCCESS, "OK", timeout);
637630
}
638631

639-
/**
640-
* Public API - Abort this connection and all its channels
641-
*/
642-
public void abort()
632+
public void close(int closeCode, String closeMessage)
633+
throws IOException
643634
{
644-
abort(-1);
635+
close(closeCode, closeMessage, -1);
645636
}
646637

647-
public void abort(int timeout)
638+
public void close(int closeCode, String closeMessage, int timeout)
639+
throws IOException
648640
{
641+
close(closeCode, closeMessage, true, null, timeout, false);
642+
}
649643

650-
try {
651-
close(200, "Goodbye", true, null, timeout, true);
652-
} catch (IOException e) {
653-
Utility.emptyStatement();
654-
}
644+
public void abort()
645+
{
646+
abort(-1);
655647
}
656648

657-
/**
658-
* Protected API - Close this connection with the given code and message.
659-
* See the comments in ChannelN.close() - we're very similar.
660-
*/
661-
public void close(int closeCode, String closeMessage)
662-
throws IOException
649+
public void abort(int closeCode, String closeMessage)
663650
{
664-
close(closeCode, closeMessage, 0);
651+
abort(closeCode, closeMessage, -1);
665652
}
666653

667-
public void close(int closeCode, String closeMessage, int timeout)
668-
throws IOException
654+
public void abort(int timeout)
669655
{
670-
close(closeCode, closeMessage, true, null, timeout, false);
656+
abort(AMQP.REPLY_SUCCESS, "OK", timeout);
671657
}
672658

659+
public void abort(int closeCode, String closeMessage, int timeout)
660+
{
661+
try {
662+
close(closeCode, closeMessage, true, null, timeout, true);
663+
} catch (IOException e) {
664+
Utility.emptyStatement();
665+
}
666+
}
667+
673668
public void close(int closeCode,
674669
String closeMessage,
675670
boolean initiatedByApplication,
@@ -680,7 +675,9 @@ public void close(int closeCode,
680675
}
681676

682677
/**
683-
* Protected API - Close this connection with the given code, message and source.
678+
* Protected API - Close this connection with the given code, message, source
679+
* and timeout value for all the close operations to complete.
680+
* Specifies if any encountered exceptions should be ignored.
684681
*/
685682
public void close(int closeCode,
686683
String closeMessage,

src/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Map;
3232
import java.util.concurrent.TimeoutException;
3333

34+
import com.rabbitmq.client.AMQP;
3435
import com.rabbitmq.client.Command;
3536
import com.rabbitmq.client.Connection;
3637
import com.rabbitmq.client.Consumer;
@@ -248,19 +249,22 @@ public void releaseChannelNumber() {
248249
}
249250
}
250251

251-
/**
252-
* Public API - closes this channel with the given code and message
253-
*/
252+
public void close()
253+
throws IOException
254+
{
255+
close(AMQP.REPLY_SUCCESS, "OK");
256+
}
257+
254258
public void close(int closeCode, String closeMessage)
255259
throws IOException
256260
{
257261
close(closeCode, closeMessage, true, null);
258262
}
259263

260264
/**
261-
* Protected API - close channel with code and message, indicating
265+
* Protected API - Close channel with code and message, indicating
262266
* the source of the closure and a causing exception (null if
263-
* none)
267+
* none).
264268
*/
265269
public void close(int closeCode,
266270
String closeMessage,

test/src/com/rabbitmq/client/test/Bug19219Test.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@
2828
import java.util.concurrent.CountDownLatch;
2929
import java.util.concurrent.Semaphore;
3030

31-
import junit.framework.TestCase;
3231
import junit.framework.TestSuite;
3332

34-
import com.rabbitmq.client.AMQP;
3533
import com.rabbitmq.client.Channel;
3634
import com.rabbitmq.client.Connection;
3735
import com.rabbitmq.client.Consumer;
3836
import com.rabbitmq.client.DefaultConsumer;
3937
import com.rabbitmq.client.MessageProperties;
4038
import com.rabbitmq.client.ShutdownSignalException;
41-
4239
import com.rabbitmq.client.test.functional.BrokerTestCase;
4340

4441
/**
@@ -136,7 +133,7 @@ public void run() {
136133
//notifications timing out.
137134
boolean success = false;
138135
try {
139-
channel.close(AMQP.REPLY_SUCCESS, "bye");
136+
channel.close();
140137
success = true;
141138
} catch (ShutdownSignalException e) {
142139
} finally {

test/src/com/rabbitmq/client/test/functional/BrokerTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void closeChannel()
6969
throws IOException
7070
{
7171
if (channel != null) {
72-
channel.close(200, "OK");
72+
channel.close();
7373
channel = null;
7474
}
7575
}

test/src/com/rabbitmq/client/test/functional/PersisterRestart1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected void tearDown()
5050
throws IOException
5151
{
5252
if (channel2 != null) {
53-
channel2.close(200, "OK");
53+
channel2.close();
5454
channel2 = null;
5555
}
5656
super.tearDown();

test/src/com/rabbitmq/examples/ConsumerMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void runIt() throws IOException {
126126
channel.queueDelete(ticket, completionQueue);
127127

128128
System.out.println("Closing the channel.");
129-
channel.close(200, "Closing channel with no error");
129+
channel.close();
130130

131131
System.out.println("Closing the connection.");
132132
_connection.close();

test/src/com/rabbitmq/examples/ProducerMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private void runIt() throws IOException {
163163
_channel.txCommit();
164164
}
165165

166-
_channel.close(200, "Closing ch1 with no error");
166+
_channel.close();
167167
System.out.println("Closing.");
168168
_connection.close();
169169
System.out.println("Leaving ProducerMain.run().");

test/src/com/rabbitmq/examples/SendString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void main(String[] args) {
5151

5252
ch.exchangeDeclare(ticket, exchange, exchangeType);
5353
ch.basicPublish(ticket, exchange, routingKey, null, message.getBytes());
54-
ch.close(200, "Closing the channel");
54+
ch.close();
5555
conn.close();
5656
} catch (Exception e) {
5757
System.err.println("Main thread caught exception: " + e);

0 commit comments

Comments
 (0)