|
17 | 17 |
|
18 | 18 | import com.rabbitmq.client.*;
|
19 | 19 | import com.rabbitmq.client.impl.AMQCommand;
|
| 20 | +import com.rabbitmq.client.impl.recovery.Utils.IoTimeoutExceptionRunnable; |
20 | 21 | import org.slf4j.Logger;
|
21 | 22 | import org.slf4j.LoggerFactory;
|
22 | 23 |
|
@@ -69,33 +70,41 @@ public Channel getDelegate() {
|
69 | 70 |
|
70 | 71 | @Override
|
71 | 72 | public void close() throws IOException, TimeoutException {
|
72 |
| - try { |
73 |
| - delegate.close(); |
74 |
| - } finally { |
75 |
| - for (String consumerTag : consumerTags) { |
76 |
| - this.connection.deleteRecordedConsumer(consumerTag); |
77 |
| - } |
78 |
| - this.connection.unregisterChannel(this); |
79 |
| - } |
| 73 | + executeAndClean(() -> delegate.close()); |
80 | 74 | }
|
81 | 75 |
|
82 | 76 | @Override
|
83 | 77 | public void close(int closeCode, String closeMessage) throws IOException, TimeoutException {
|
84 |
| - try { |
85 |
| - delegate.close(closeCode, closeMessage); |
86 |
| - } finally { |
87 |
| - this.connection.unregisterChannel(this); |
88 |
| - } |
| 78 | + executeAndClean(() -> delegate.close(closeCode, closeMessage)); |
89 | 79 | }
|
90 | 80 |
|
91 | 81 | @Override
|
92 | 82 | public void abort() throws IOException {
|
93 |
| - delegate.abort(); |
| 83 | + try { |
| 84 | + executeAndClean(() -> delegate.abort()); |
| 85 | + } catch (TimeoutException e) { |
| 86 | + // abort() ignores exceptions |
| 87 | + } |
94 | 88 | }
|
95 | 89 |
|
96 | 90 | @Override
|
97 | 91 | public void abort(int closeCode, String closeMessage) throws IOException {
|
98 |
| - delegate.abort(closeCode, closeMessage); |
| 92 | + try { |
| 93 | + executeAndClean(() -> delegate.abort(closeCode, closeMessage)); |
| 94 | + } catch (TimeoutException e) { |
| 95 | + // abort() ignores exceptions |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + private void executeAndClean(IoTimeoutExceptionRunnable callback) throws IOException, TimeoutException { |
| 100 | + try { |
| 101 | + callback.run(); |
| 102 | + } finally { |
| 103 | + for (String consumerTag : consumerTags) { |
| 104 | + this.connection.deleteRecordedConsumer(consumerTag); |
| 105 | + } |
| 106 | + this.connection.unregisterChannel(this); |
| 107 | + } |
99 | 108 | }
|
100 | 109 |
|
101 | 110 | @Override
|
|
0 commit comments