Skip to content

Commit 820c13d

Browse files
author
Hubert Plociniczak
committed
Added Channel.Close method that sets default
AMQP.REPLY_SUCCESS code and Goodbye message. Use this variable in Connection close methods instead of hardcoded 200 value.
1 parent fac60a6 commit 820c13d

File tree

12 files changed

+37
-30
lines changed

12 files changed

+37
-30
lines changed

src/com/rabbitmq/client/Channel.java

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

7272
/**
73-
* Close this channel with the given code and message
74-
* @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
73+
* Close this channel with the default code and message
7674
* @throws java.io.IOException if an error is encountered
7775
*/
78-
void close(int closeCode, String closeMessage) throws IOException;
76+
void close() throws IOException;
7977

8078
/**
8179
* Return the current {@link ReturnListener}.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ public void close()
632632
public void close(int timeout)
633633
throws IOException
634634
{
635-
close(200, "Goodbye", timeout);
635+
close(AMQP.REPLY_SUCCESS, "Goodbye", timeout);
636636
}
637637

638638
/**
@@ -647,7 +647,7 @@ public void abort(int timeout)
647647
{
648648

649649
try {
650-
close(200, "Goodbye", true, null, timeout, true);
650+
close(AMQP.REPLY_SUCCESS, "Goodbye", true, null, timeout, true);
651651
} catch (IOException e) {
652652
Utility.emptyStatement();
653653
}

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

Lines changed: 13 additions & 1 deletion
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,8 +249,19 @@ public void releaseChannelNumber() {
248249
}
249250
}
250251

252+
253+
/**
254+
* Public API - closes this channel with the default 200 close code
255+
* and 'Goodbye' message
256+
*/
257+
public void close()
258+
throws IOException
259+
{
260+
close(AMQP.REPLY_SUCCESS, "Goodbye");
261+
}
262+
251263
/**
252-
* Public API - closes this channel with the given code and message
264+
* Protected API - closes this channel with the given code and message
253265
*/
254266
public void close(int closeCode, String closeMessage)
255267
throws IOException

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);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void main(String[] args) {
4949
ch.queueDeclare(ticket, routingKey);
5050
}
5151
ch.basicPublish(ticket, exchange, routingKey, null, message.getBytes());
52-
ch.close(200, "Closing the channel");
52+
ch.close();
5353
conn.close();
5454
} catch (Exception e) {
5555
System.err.println("Main thread caught exception: " + e);

0 commit comments

Comments
 (0)