diff options
author | Alan Conway <aconway@apache.org> | 2008-08-07 13:45:24 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-08-07 13:45:24 +0000 |
commit | ed5d40386e04fd75ea8051102abcb3a1f1f53ddd (patch) | |
tree | 906434b6856197020bd711bedfd0c634134b66cd /cpp/src | |
parent | 469dbf73971b247af0659f8dfdf1b15c6724d11a (diff) | |
download | qpid-python-ed5d40386e04fd75ea8051102abcb3a1f1f53ddd.tar.gz |
Patch from Gordon Sim to fix issues with hasOutput implementation.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@683617 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/broker/Queue.cpp | 25 | ||||
-rw-r--r-- | cpp/src/qpid/broker/Queue.h | 12 | ||||
-rw-r--r-- | cpp/src/qpid/broker/SemanticState.cpp | 3 |
3 files changed, 32 insertions, 8 deletions
diff --git a/cpp/src/qpid/broker/Queue.cpp b/cpp/src/qpid/broker/Queue.cpp index 3b447e97f2..acab1e06f1 100644 --- a/cpp/src/qpid/broker/Queue.cpp +++ b/cpp/src/qpid/broker/Queue.cpp @@ -212,9 +212,30 @@ bool Queue::getNextMessage(QueuedMessage& m, Consumer& c) } } -bool Queue::empty() const { +bool Queue::checkForMessages(Consumer& c) +{ Mutex::ScopedLock locker(messageLock); - return messages.empty(); + if (messages.empty()) { + //no message available, register consumer for notification + //when this changes + addListener(c); + return false; + } else { + QueuedMessage msg = messages.front(); + if (store && !msg.payload->isEnqueueComplete()) { + //though a message is on the queue, it has not yet been + //enqueued and so is not available for consumption yet, + //register consumer for notification when this changes + addListener(c); + return false; + } else { + //check that consumer has sufficient credit for the + //message (if it does not, no need to register it for + //notification as the consumer itself will handle the + //credit allocation required to change this condition). + return c.accept(msg.payload); + } + } } bool Queue::consumeNextMessage(QueuedMessage& m, Consumer& c) diff --git a/cpp/src/qpid/broker/Queue.h b/cpp/src/qpid/broker/Queue.h index e35b3ef7ee..347fc5cf9d 100644 --- a/cpp/src/qpid/broker/Queue.h +++ b/cpp/src/qpid/broker/Queue.h @@ -107,6 +107,7 @@ namespace qpid { void notify(); void removeListener(Consumer&); + void addListener(Consumer&); bool isExcluded(boost::intrusive_ptr<Message>& msg); @@ -114,8 +115,6 @@ namespace qpid { void popAndDequeue(); public: - // FIXME aconway 2008-08-06: was private, verify if needed public. - void addListener(Consumer&); virtual void notifyDurableIOComplete(); typedef boost::shared_ptr<Queue> shared_ptr; @@ -128,9 +127,14 @@ namespace qpid { management::Manageable* parent = 0); ~Queue(); - bool empty() const; - bool dispatch(Consumer&); + /** + * Check whether there would be a message available for + * dispatch to this consumer. If not, the consumer will be + * notified of events that may have changed this + * situation. + */ + bool checkForMessages(Consumer&); void create(const qpid::framing::FieldTable& settings); void configure(const qpid::framing::FieldTable& settings); diff --git a/cpp/src/qpid/broker/SemanticState.cpp b/cpp/src/qpid/broker/SemanticState.cpp index bf034a0559..4d5c4e7537 100644 --- a/cpp/src/qpid/broker/SemanticState.cpp +++ b/cpp/src/qpid/broker/SemanticState.cpp @@ -591,8 +591,7 @@ void SemanticState::reject(DeliveryId first, DeliveryId last) } bool SemanticState::ConsumerImpl::hasOutput() { - queue->addListener(*this); - return !queue->empty(); + return queue->checkForMessages(*this); } bool SemanticState::ConsumerImpl::doOutput() |