|
19 | 19 | import java.io.IOException; |
20 | 20 |
|
21 | 21 | import com.rabbitmq.client.AMQP; |
| 22 | +import com.rabbitmq.client.AlreadyClosedException; |
22 | 23 | import com.rabbitmq.client.Channel; |
23 | 24 | import com.rabbitmq.client.Connection; |
24 | 25 | import com.rabbitmq.client.Consumer; |
25 | 26 |
|
| 27 | +/** |
| 28 | + * Default implementation of {@link ExceptionHandler} used by {@link AMQConnection}. |
| 29 | + */ |
26 | 30 | public class DefaultExceptionHandler implements ExceptionHandler { |
27 | 31 | public void handleUnexpectedConnectionDriverException(Connection conn, Throwable exception) { |
28 | 32 | // TODO: Log this somewhere, just in case we have a bug like |
@@ -55,23 +59,21 @@ public void handleConsumerException(Channel channel, Throwable exception, |
55 | 59 | + " for channel " + channel); |
56 | 60 | } |
57 | 61 |
|
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 + ":"); |
65 | 66 | exception.printStackTrace(); |
66 | 67 | 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 |
71 | 71 | } 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); |
74 | 77 | } |
75 | | - |
76 | 78 | } |
77 | 79 | } |
0 commit comments