diff options
| author | Ted Ross <tross@apache.org> | 2013-03-13 18:34:58 +0000 |
|---|---|---|
| committer | Ted Ross <tross@apache.org> | 2013-03-13 18:34:58 +0000 |
| commit | 3bc62d5669af79a7ca4a2064bf7482b90df976d3 (patch) | |
| tree | fdb3c1af92e6d5086cf1fa2b6f56cfa6b9f33142 /cpp/src/qpid | |
| parent | dc824fd68a48a61d276278cda9853a7e90e48290 (diff) | |
| download | qpid-python-3bc62d5669af79a7ca4a2064bf7482b90df976d3.tar.gz | |
QPID-4559 - Added handling of the queue-delete preconditions in the qmf broker method.
Patch contributed by Ernie Allen.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1456081 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid')
| -rw-r--r-- | cpp/src/qpid/broker/Broker.cpp | 23 | ||||
| -rw-r--r-- | cpp/src/qpid/broker/Broker.h | 1 |
2 files changed, 23 insertions, 1 deletions
diff --git a/cpp/src/qpid/broker/Broker.cpp b/cpp/src/qpid/broker/Broker.cpp index 47296d94b0..a9887f9c35 100644 --- a/cpp/src/qpid/broker/Broker.cpp +++ b/cpp/src/qpid/broker/Broker.cpp @@ -624,6 +624,10 @@ const std::string SRC_IS_QUEUE("srcIsQueue"); const std::string SRC_IS_LOCAL("srcIsLocal"); const std::string DYNAMIC("dynamic"); const std::string SYNC("sync"); + +// parameters for deleting a Queue object +const std::string IF_EMPTY("if_empty"); +const std::string IF_UNUSED("if_unused"); } struct InvalidBindingIdentifier : public qpid::Exception @@ -890,7 +894,14 @@ void Broker::deleteObject(const std::string& type, const std::string& name, } QPID_LOG (debug, "Broker::delete(" << type << ", " << name << "," << options << ")"); if (type == TYPE_QUEUE) { - deleteQueue(name, userId, connectionId); + // extract ifEmpty and ifUnused from options + bool ifUnused = false, ifEmpty = false; + for (Variant::Map::const_iterator i = options.begin(); i != options.end(); ++i) { + if (i->first == IF_UNUSED) ifUnused = i->second.asBool(); + else if (i->first == IF_EMPTY) ifEmpty = i->second.asBool(); + } + deleteQueue(name, userId, connectionId, + boost::bind(&Broker::checkDeleteQueue, this, _1, ifUnused, ifEmpty)); } else if (type == TYPE_EXCHANGE || type == TYPE_TOPIC) { deleteExchange(name, userId, connectionId); } else if (type == TYPE_BINDING) { @@ -909,7 +920,17 @@ void Broker::deleteObject(const std::string& type, const std::string& name, } else { throw UnknownObjectType(type); } +} +void Broker::checkDeleteQueue(Queue::shared_ptr queue, bool ifUnused, bool ifEmpty) +{ + if(ifEmpty && queue->getMessageCount() > 0) { + throw qpid::framing::PreconditionFailedException(QPID_MSG("Cannot delete queue " + << queue->getName() << "; queue not empty")); + } else if(ifUnused && queue->getConsumerCount() > 0) { + throw qpid::framing::PreconditionFailedException(QPID_MSG("Cannot delete queue " + << queue->getName() << "; queue in use")); + } } Manageable::status_t Broker::queryObject(const std::string& type, diff --git a/cpp/src/qpid/broker/Broker.h b/cpp/src/qpid/broker/Broker.h index be2b9bef75..cfd96c9913 100644 --- a/cpp/src/qpid/broker/Broker.h +++ b/cpp/src/qpid/broker/Broker.h @@ -152,6 +152,7 @@ class Broker : public sys::Runnable, public Plugin::Target, const qpid::types::Variant::Map& properties, bool strict, const ConnectionState* context); void deleteObject(const std::string& type, const std::string& name, const qpid::types::Variant::Map& options, const ConnectionState* context); + void checkDeleteQueue(boost::shared_ptr<Queue> queue, bool ifUnused, bool ifEmpty); Manageable::status_t queryObject(const std::string& type, const std::string& name, qpid::types::Variant::Map& results, const ConnectionState* context); Manageable::status_t queryQueue( const std::string& name, |
