|
37 | 37 | import com.rabbitmq.client.Connection; |
38 | 38 | import com.rabbitmq.client.Consumer; |
39 | 39 | import com.rabbitmq.client.Envelope; |
| 40 | +import com.rabbitmq.client.FlowListener; |
40 | 41 | import com.rabbitmq.client.GetResponse; |
41 | 42 | import com.rabbitmq.client.MessageProperties; |
42 | 43 | import com.rabbitmq.client.ReturnListener; |
@@ -93,6 +94,10 @@ public class ChannelN extends AMQChannel implements com.rabbitmq.client.Channel |
93 | 94 | */ |
94 | 95 | public volatile ReturnListener returnListener = null; |
95 | 96 |
|
| 97 | + /** Reference to the currently-active FlowListener, or null if there is none. |
| 98 | + */ |
| 99 | + public volatile FlowListener flowListener = null; |
| 100 | + |
96 | 101 | /** |
97 | 102 | * Construct a new channel on the given connection with the given |
98 | 103 | * channel number. Usually not called directly - call |
@@ -130,6 +135,19 @@ public void setReturnListener(ReturnListener listener) { |
130 | 135 | returnListener = listener; |
131 | 136 | } |
132 | 137 |
|
| 138 | + /** Returns the current FlowListener. */ |
| 139 | + public FlowListener getFlowListener() { |
| 140 | + return flowListener; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * Sets the current FlowListener. |
| 145 | + * A null argument is interpreted to mean "do not use a flow listener". |
| 146 | + */ |
| 147 | + public void setFlowListener(FlowListener listener) { |
| 148 | + flowListener = listener; |
| 149 | + } |
| 150 | + |
133 | 151 | /** |
134 | 152 | * Protected API - sends a ShutdownSignal to all active consumers. |
135 | 153 | * @param signal an exception signalling channel shutdown |
@@ -171,7 +189,8 @@ public void releaseChannelNumber() { |
171 | 189 |
|
172 | 190 | /** |
173 | 191 | * Protected API - Filters the inbound command stream, processing |
174 | | - * Basic.Deliver, Basic.Return and Channel.Close specially. |
| 192 | + * Basic.Deliver, Basic.Return, Channel.Flow and Channel.Close |
| 193 | + * specially. |
175 | 194 | */ |
176 | 195 | @Override public boolean processAsync(Command command) throws IOException |
177 | 196 | { |
@@ -257,6 +276,14 @@ public void releaseChannelNumber() { |
257 | 276 | transmit(new Channel.FlowOk(channelFlow.active)); |
258 | 277 | _channelMutex.notifyAll(); |
259 | 278 | } |
| 279 | + FlowListener l = getFlowListener(); |
| 280 | + if (l != null) { |
| 281 | + try { |
| 282 | + l.handleFlow(channelFlow.active); |
| 283 | + } catch (Throwable ex) { |
| 284 | + _connection.getExceptionHandler().handleFlowListenerException(this, ex); |
| 285 | + } |
| 286 | + } |
260 | 287 | return true; |
261 | 288 | } else { |
262 | 289 | return false; |
@@ -704,4 +731,10 @@ public Tx.RollbackOk txRollback() |
704 | 731 | public Channel.FlowOk flow(final boolean a) throws IOException { |
705 | 732 | return (Channel.FlowOk) exnWrappingRpc(new Channel.Flow() {{active = a;}}).getMethod(); |
706 | 733 | } |
| 734 | + |
| 735 | + /** Public API - {@inheritDoc} */ |
| 736 | + public Channel.FlowOk getFlow() { |
| 737 | + return new Channel.FlowOk(!_blockContent); |
| 738 | + } |
| 739 | + |
707 | 740 | } |
0 commit comments