diff options
| author | Gordon Sim <gsim@apache.org> | 2013-11-12 13:42:36 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2013-11-12 13:42:36 +0000 |
| commit | 5f3ff3bcc03691d0646cd75d8408be284d8adee6 (patch) | |
| tree | d475768bd96b23ac17771b1b9d8617b2790d83e5 /cpp/src/qpid/broker/DirectExchange.cpp | |
| parent | 3741945c58f6b835003bbdb978efa34ff6a681b5 (diff) | |
| download | qpid-python-5f3ff3bcc03691d0646cd75d8408be284d8adee6.tar.gz | |
QPID-5301: support autodeleted exchanges
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1541058 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/broker/DirectExchange.cpp')
| -rw-r--r-- | cpp/src/qpid/broker/DirectExchange.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/cpp/src/qpid/broker/DirectExchange.cpp b/cpp/src/qpid/broker/DirectExchange.cpp index 8ab7b59ed1..65c8287d4f 100644 --- a/cpp/src/qpid/broker/DirectExchange.cpp +++ b/cpp/src/qpid/broker/DirectExchange.cpp @@ -45,9 +45,9 @@ DirectExchange::DirectExchange(const string& _name, Manageable* _parent, Broker* mgmtExchange->set_type(typeName); } -DirectExchange::DirectExchange(const string& _name, bool _durable, +DirectExchange::DirectExchange(const string& _name, bool _durable, bool autodelete, const FieldTable& _args, Manageable* _parent, Broker* b) : - Exchange(_name, _durable, _args, _parent, b) + Exchange(_name, _durable, autodelete, _args, _parent, b) { if (mgmtExchange != 0) mgmtExchange->set_type(typeName); @@ -131,6 +131,7 @@ bool DirectExchange::unbind(Queue::shared_ptr queue, const string& routingKey, c { string fedOrigin(args ? args->getAsString(qpidFedOrigin) : ""); bool propagate = false; + bool empty = false; QPID_LOG(debug, "Unbinding key [" << routingKey << "] from queue " << queue->getName() << " on exchange " << getName() << " origin=" << fedOrigin << ")" ); @@ -144,6 +145,7 @@ bool DirectExchange::unbind(Queue::shared_ptr queue, const string& routingKey, c } if (bk.queues.empty()) { bindings.erase(routingKey); + if (bindings.empty()) empty = true; } } else { return false; @@ -153,6 +155,7 @@ bool DirectExchange::unbind(Queue::shared_ptr queue, const string& routingKey, c // If I delete my local binding, propagate this unbind to any upstream brokers if (propagate) propagateFedOp(routingKey, string(), fedOpUnbind, string()); + if (empty) checkAutodelete(); return true; } @@ -163,7 +166,8 @@ void DirectExchange::route(Deliverable& msg) ConstBindingList b; { Mutex::ScopedLock l(lock); - b = bindings[routingKey].queues.snapshot(); + Bindings::iterator i = bindings.find(routingKey); + if (i != bindings.end()) b = i->second.queues.snapshot(); } doRoute(msg, b); } @@ -202,3 +206,9 @@ DirectExchange::~DirectExchange() { } const std::string DirectExchange::typeName("direct"); + +bool DirectExchange::hasBindings() +{ + Mutex::ScopedLock l(lock); + return !bindings.empty(); +} |
