Skip to content

Commit 554e5e0

Browse files
author
David R. MacIver
committed
clarify logic for shutting down queue
1 parent c14fe11 commit 554e5e0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/com/rabbitmq/client/QueueingConsumer.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@
4444
*/
4545
public class QueueingConsumer extends DefaultConsumer {
4646
private final BlockingQueue<Delivery> _queue;
47+
48+
// When this is non-null the queue is in shutdown mode and nextDelivery should
49+
// throw a shutdown signal exception.
4750
private volatile ShutdownSignalException _shutdown;
4851

4952
// Marker object used to signal the queue is in shutdown mode.
53+
// It is only there to wake up consumers. The canonical representation
54+
// of shutting down is the presence of _shutdown.
5055
// Invariant: This is never on _queue unless _shutdown != null.
5156
private static final Delivery POISON = new Delivery(null, null, null);
5257

@@ -113,10 +118,18 @@ public byte[] getBody() {
113118
}
114119
}
115120

121+
/**
122+
* Check if we are in shutdown mode and if so throw an exception.
123+
*/
116124
private void checkShutdown(){
117-
if(_shutdown != null) throw _shutdown;
125+
if(_shutdown != null) throw Utility.fixStackTrace(_shutdown);
118126
}
119127

128+
/**
129+
* If this is a non-POISON non-null delivery simply return it.
130+
* If this is POISON we are in shutdown mode, throw _shutdown
131+
* If this is null, we may be in shutdown mode. Check and see.
132+
*/
120133
private Delivery handle(Delivery delivery)
121134
{
122135
if(delivery == POISON || (delivery == null && _shutdown != null)){

0 commit comments

Comments
 (0)