Skip to content

Commit cb64611

Browse files
committed
merge bug19676 into default
2 parents b3e3418 + d4e4089 commit cb64611

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ public interface Channel extends ShutdownNotifier{
8484
* @throws java.io.IOException if an error is encountered
8585
*/
8686
void close(int closeCode, String closeMessage) throws IOException;
87+
88+
/**
89+
* Abort this channel with the {@link com.rabbitmq.client.AMQP#REPLY_SUCCESS} close code
90+
* and message 'OK'.
91+
*
92+
* Forces the channel to close and waits for the close operation to complete.
93+
* Any encountered exceptions in the close operation are silently discarded.
94+
*/
95+
void abort() throws IOException;
96+
97+
/**
98+
* Abort this channel.
99+
*
100+
* Forces the channel to close and waits for the close operation to complete.
101+
* Any encountered exceptions in the close operation are silently discarded.
102+
*/
103+
void abort(int closeCode, String closeMessage) throws IOException;
87104

88105
/**
89106
* Return the current {@link ReturnListener}.

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

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,19 @@ public void close()
278278
public void close(int closeCode, String closeMessage)
279279
throws IOException
280280
{
281-
close(closeCode, closeMessage, true, null);
281+
close(closeCode, closeMessage, true, null, false);
282+
}
283+
284+
public void abort()
285+
throws IOException
286+
{
287+
abort(AMQP.REPLY_SUCCESS, "OK");
288+
}
289+
290+
public void abort(int closeCode, String closeMessage)
291+
throws IOException
292+
{
293+
close(closeCode, closeMessage, true, null, true);
282294
}
283295

284296
/**
@@ -289,7 +301,8 @@ public void close(int closeCode, String closeMessage)
289301
public void close(int closeCode,
290302
String closeMessage,
291303
boolean initiatedByApplication,
292-
Throwable cause)
304+
Throwable cause,
305+
boolean abort)
293306
throws IOException
294307
{
295308
// First, notify all our dependents that we are shutting down.
@@ -306,29 +319,38 @@ public void close(int closeCode,
306319
}
307320

308321
BlockingRpcContinuation<AMQCommand> k = new SimpleBlockingRpcContinuation();
309-
// Synchronize the block below to avoid race conditions in case
310-
// connnection wants to send Connection-CloseOK
311-
synchronized(this) {
312-
processShutdownSignal(signal, !initiatedByApplication, true);
313-
quiescingRpc(reason, k);
314-
}
315-
322+
boolean notify = false;
316323
try {
324+
// Synchronize the block below to avoid race conditions in case
325+
// connnection wants to send Connection-CloseOK
326+
synchronized(this) {
327+
processShutdownSignal(signal, !initiatedByApplication, true);
328+
quiescingRpc(reason, k);
329+
}
330+
317331
// Now that we're in quiescing state, channel.close was sent and
318332
// we wait for the reply. We ignore the result. (It's always
319333
// close-ok.)
334+
notify = true;
320335
k.getReply(-1);
321336
} catch (TimeoutException ise) {
322337
// Will never happen since we wait infinitely
338+
} catch (ShutdownSignalException sse) {
339+
if (!abort)
340+
throw sse;
341+
} catch (IOException ioe) {
342+
if (!abort)
343+
throw ioe;
323344
} finally {
324-
325-
// Now we know everything's been cleaned up and there should
326-
// be no more surprises arriving on the wire. Release the
327-
// channel number, and dissociate this ChannelN instance from
328-
// our connection so that any further frames inbound on this
329-
// channel can be caught as the errors they are.
330-
releaseChannelNumber();
331-
notifyListeners();
345+
if (abort || notify) {
346+
// Now we know everything's been cleaned up and there should
347+
// be no more surprises arriving on the wire. Release the
348+
// channel number, and dissociate this ChannelN instance from
349+
// our connection so that any further frames inbound on this
350+
// channel can be caught as the errors they are.
351+
releaseChannelNumber();
352+
notifyListeners();
353+
}
332354
}
333355
}
334356

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import junit.framework.TestCase;
3131

32-
import com.rabbitmq.client.AlreadyClosedException;
3332
import com.rabbitmq.client.Channel;
3433
import com.rabbitmq.client.Connection;
3534
import com.rabbitmq.client.ConnectionFactory;
@@ -110,12 +109,7 @@ public void closeChannel()
110109
throws IOException
111110
{
112111
if (channel != null) {
113-
try {
114-
channel.close();
115-
} catch (AlreadyClosedException ace) {
116-
// The API is broken so we have to catch this here.
117-
// See bug 19676.
118-
}
112+
channel.abort();
119113
channel = null;
120114
}
121115
}

0 commit comments

Comments
 (0)