Skip to content

Commit 72b6e74

Browse files
author
Emile Joubert
committed
Merged bug24910 into default
2 parents 4547642 + 6f90ef0 commit 72b6e74

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/com/rabbitmq/client/AlreadyClosedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.rabbitmq.client;
1919

20-
/*
20+
/**
2121
* Thrown when application tries to perform an action on connection/channel
2222
* which was already closed
2323
*/

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
import java.io.IOException;
2020

2121
import com.rabbitmq.client.AMQP;
22+
import com.rabbitmq.client.AlreadyClosedException;
2223
import com.rabbitmq.client.Channel;
2324
import com.rabbitmq.client.Connection;
2425
import com.rabbitmq.client.Consumer;
2526

27+
/**
28+
* Default implementation of {@link ExceptionHandler} used by {@link AMQConnection}.
29+
*/
2630
public class DefaultExceptionHandler implements ExceptionHandler {
2731
public void handleUnexpectedConnectionDriverException(Connection conn, Throwable exception) {
2832
// TODO: Log this somewhere, just in case we have a bug like
@@ -55,23 +59,21 @@ public void handleConsumerException(Channel channel, Throwable exception,
5559
+ " for channel " + channel);
5660
}
5761

58-
protected void handleChannelKiller(Channel channel,
59-
Throwable exception,
60-
String what)
61-
{
62-
// TODO: Convert to logging framework
63-
System.err.println(what + " threw an exception for channel " +
64-
channel + ":");
62+
protected void handleChannelKiller(Channel channel, Throwable exception, String what) {
63+
// TODO: log the exception
64+
System.err.println("DefaultExceptionHandler: " + what + " threw an exception for channel "
65+
+ channel + ":");
6566
exception.printStackTrace();
6667
try {
67-
((AMQConnection) channel.getConnection()).close(AMQP.INTERNAL_ERROR,
68-
"Internal error in " + what,
69-
false,
70-
exception);
68+
channel.close(AMQP.REPLY_SUCCESS, "Closed due to exception from " + what);
69+
} catch (AlreadyClosedException ace) {
70+
// noop
7171
} catch (IOException ioe) {
72-
// Man, this clearly isn't our day.
73-
// Ignore the exception? TODO: Log the nested failure
72+
// TODO: log the failure
73+
System.err.println("Failure during close of channel " + channel + " after " + exception
74+
+ ":");
75+
ioe.printStackTrace();
76+
channel.getConnection().abort(AMQP.INTERNAL_ERROR, "Internal error closing channel for " + what);
7477
}
75-
7678
}
7779
}

0 commit comments

Comments
 (0)