Skip to content

Commit 3063f21

Browse files
author
Hubert Plociniczak
committed
Improved Connection and Channel API to contain
all the necessary methods related to closing. Fixed typos.
1 parent 820c13d commit 3063f21

File tree

4 files changed

+124
-33
lines changed

4 files changed

+124
-33
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,20 @@ public interface Channel extends ShutdownNotifier{
7070
Connection getConnection();
7171

7272
/**
73-
* Close this channel with the default code and message
73+
* Close this channel with the default close code and message.
74+
*
7475
* @throws java.io.IOException if an error is encountered
7576
*/
7677
void close() throws IOException;
78+
79+
/**
80+
* Close this channel.
81+
*
82+
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
83+
* @param closeMessage a message indicating the reason for closing the connection
84+
* @throws java.io.IOException if an error is encountered
85+
*/
86+
void close(int closeCode, String closeMessage) throws IOException;
7787

7888
/**
7989
* Return the current {@link ReturnListener}.

src/com/rabbitmq/client/Connection.java

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,44 +121,101 @@ 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 default close code and message.
125126
*
126127
* This method will wait infinitely for all the close operations to
127128
* 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+
* This method will wait infinitely for all the close operations to
138+
* complete.
139+
*
140+
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
141+
* @param closeMessage a message indicating the reason for closing the connection
142+
* @throws IOException if an I/O problem is encountered
143+
*/
144+
void close(int closeCode, String closeMessage) throws IOException;
132145

133146
/**
134147
* Close this connection and all its channels
148+
* with the default close code and message.
135149
*
136150
* This method will wait with the given timeout for all the close
137151
* 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
152+
* 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+
* This method will wait with the given timeout for all the close
164+
* operations to complete. If timeout is reached then socket is forced
165+
* to close.
166+
*
167+
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
168+
* @param closeMessage a message indicating the reason for closing the connection
169+
* @param timeout timeout (in milliseconds) for completing all the close-related
170+
* operations, use -1 for infinity
171+
* @throws IOException if an I/O problem is encountered
172+
*/
173+
void close(int closeCode, String closeMessage, int timeout) throws IOException;
144174

145175
/**
146-
* Abort this connection and all its channels.
176+
* Abort this connection and all its channels
177+
* with the default code and message.
147178
*
148179
* This method will force the connection to close. It will silently discard
149-
* any exceptions enountered in close operations
180+
* any exceptions encountered in close operations.
150181
*/
151182
void abort();
152-
183+
153184
/**
154185
* Abort this connection and all its channels.
155186
*
187+
* This method will force the connection to close. It will silently discard
188+
* any exceptions encountered in close operations.
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 default close code and message.
198+
*
156199
* This method behaves in a similar way as abort(), with the only difference
157200
* that it will wait with a provided timeout for all the close operations to
158201
* complete. If timeout is reached socket is forced to close.
159202
*
160-
* @param timeout timeout (in miliseconds) for completing all the close-related
203+
* @param timeout timeout (in milliseconds) for completing all the close-related
161204
* operations, use -1 for infinity
162205
*/
163206
void abort(int timeout);
207+
208+
/**
209+
* Abort this connection and all its channels.
210+
*
211+
* This method behaves in a similar way as abort(), with the only difference
212+
* that it will wait with a provided timeout for all the close operations to
213+
* complete. If timeout is reached socket is forced to close.
214+
*
215+
* @param closeCode the close code (See under "Reply Codes" in the AMQP specification)
216+
* @param closeMessage a message indicating the reason for closing the connection
217+
* @param timeout timeout (in milliseconds) for completing all the close-related
218+
* operations, use -1 for infinity
219+
*/
220+
void abort(int closeCode, String closeMessage, int timeout);
164221
}

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

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public void shutdown(Object reason,
617617
}
618618

619619
/**
620-
* Public API - Close this connection and all its channels
620+
* Public API - Close this connection and all its channels.
621621
*/
622622
public void close()
623623
throws IOException
@@ -627,48 +627,73 @@ public void close()
627627

628628
/**
629629
* Public API - Close this connection and all its channels
630-
* with a given timeout
630+
* with a given timeout.
631631
*/
632632
public void close(int timeout)
633633
throws IOException
634634
{
635635
close(AMQP.REPLY_SUCCESS, "Goodbye", timeout);
636636
}
637+
638+
/**
639+
* Public API - Close this connection and all its channels
640+
* with a given close code and message.
641+
*/
642+
public void close(int closeCode, String closeMessage)
643+
throws IOException
644+
{
645+
close(closeCode, closeMessage, -1);
646+
}
637647

638648
/**
639-
* Public API - Abort this connection and all its channels
649+
* Public API - Close this connection and all its channels
650+
* with a given close code, message and timeout.
651+
*/
652+
public void close(int closeCode, String closeMessage, int timeout)
653+
throws IOException
654+
{
655+
close(closeCode, closeMessage, true, null, timeout, false);
656+
}
657+
658+
/**
659+
* Public API - Abort this connection and all its channels.
640660
*/
641661
public void abort()
642662
{
643663
abort(-1);
644664
}
645665

646-
public void abort(int timeout)
666+
/**
667+
* Public API - Abort this connection and all its channels
668+
* with a given close code and message.
669+
*/
670+
public void abort(int closeCode, String closeMessage)
647671
{
648-
649-
try {
650-
close(AMQP.REPLY_SUCCESS, "Goodbye", true, null, timeout, true);
651-
} catch (IOException e) {
652-
Utility.emptyStatement();
653-
}
672+
abort(closeCode, closeMessage, -1);
654673
}
655674

656675
/**
657-
* Protected API - Close this connection with the given code and message.
658-
* See the comments in ChannelN.close() - we're very similar.
676+
* Public API - Abort this connection and all its channels
677+
* with a given timeout.
659678
*/
660-
public void close(int closeCode, String closeMessage)
661-
throws IOException
679+
public void abort(int timeout)
662680
{
663-
close(closeCode, closeMessage, 0);
681+
abort(AMQP.REPLY_SUCCESS, "Goodbye", timeout);
664682
}
665-
666-
public void close(int closeCode, String closeMessage, int timeout)
667-
throws IOException
683+
684+
/**
685+
* Public API - Abort this connection and all its channels
686+
* with a given close code, message and timeout.
687+
*/
688+
public void abort(int closeCode, String closeMessage, int timeout)
668689
{
669-
close(closeCode, closeMessage, true, null, timeout, false);
690+
try {
691+
close(closeCode, closeMessage, true, null, timeout, true);
692+
} catch (IOException e) {
693+
Utility.emptyStatement();
694+
}
670695
}
671-
696+
672697
public void close(int closeCode,
673698
String closeMessage,
674699
boolean initiatedByApplication,

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ public void releaseChannelNumber() {
251251

252252

253253
/**
254-
* Public API - closes this channel with the default 200 close code
255-
* and 'Goodbye' message
254+
* Public API - Close this channel with the default close code and message.
256255
*/
257256
public void close()
258257
throws IOException
@@ -261,7 +260,7 @@ public void close()
261260
}
262261

263262
/**
264-
* Protected API - closes this channel with the given code and message
263+
* Public API - Close this channel.
265264
*/
266265
public void close(int closeCode, String closeMessage)
267266
throws IOException
@@ -270,9 +269,9 @@ public void close(int closeCode, String closeMessage)
270269
}
271270

272271
/**
273-
* Protected API - close channel with code and message, indicating
272+
* Protected API - Close channel with code and message, indicating
274273
* the source of the closure and a causing exception (null if
275-
* none)
274+
* none).
276275
*/
277276
public void close(int closeCode,
278277
String closeMessage,

0 commit comments

Comments
 (0)