From ed5d40386e04fd75ea8051102abcb3a1f1f53ddd Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Thu, 7 Aug 2008 13:45:24 +0000 Subject: 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 --- cpp/src/qpid/broker/Queue.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'cpp/src/qpid/broker/Queue.cpp') 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) -- cgit v1.2.1