From 9a6c0d41b19744c8e4dc4711d13a5a0afa2f7ed2 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Thu, 17 May 2007 11:03:55 +0000 Subject: Changes to support durable exchanges. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@538872 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/broker/TopicExchange.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'cpp/src/qpid/broker/TopicExchange.cpp') diff --git a/cpp/src/qpid/broker/TopicExchange.cpp b/cpp/src/qpid/broker/TopicExchange.cpp index f29dfc38ba..4ad1607aa2 100644 --- a/cpp/src/qpid/broker/TopicExchange.cpp +++ b/cpp/src/qpid/broker/TopicExchange.cpp @@ -116,24 +116,39 @@ bool TopicPattern::match(const Tokens& target) const } TopicExchange::TopicExchange(const string& _name) : Exchange(_name) { } +TopicExchange::TopicExchange(const std::string& _name, bool _durable, const FieldTable& _args) : Exchange(_name, _durable, _args) {} -void TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, const FieldTable* /*args*/){ + +bool TopicExchange::bind(Queue::shared_ptr queue, const string& routingKey, const FieldTable* /*args*/){ Monitor::ScopedLock l(lock); TopicPattern routingPattern(routingKey); - bindings[routingPattern].push_back(queue); + if (isBound(queue, routingPattern)) { + return false; + } else { + bindings[routingPattern].push_back(queue); + return true; + } } -void TopicExchange::unbind(Queue::shared_ptr queue, const string& routingKey, const FieldTable* /*args*/){ +bool TopicExchange::unbind(Queue::shared_ptr queue, const string& routingKey, const FieldTable* /*args*/){ Monitor::ScopedLock l(lock); BindingMap::iterator bi = bindings.find(TopicPattern(routingKey)); Queue::vector& qv(bi->second); - if (bi == bindings.end()) return; + if (bi == bindings.end()) return false; Queue::vector::iterator q = find(qv.begin(), qv.end(), queue); - if(q == qv.end()) return; + if(q == qv.end()) return false; qv.erase(q); if(qv.empty()) bindings.erase(bi); + return true; } +bool TopicExchange::isBound(Queue::shared_ptr queue, TopicPattern& pattern) +{ + BindingMap::iterator bi = bindings.find(pattern); + if (bi == bindings.end()) return false; + Queue::vector& qv(bi->second); + return find(qv.begin(), qv.end(), queue) != qv.end(); +} void TopicExchange::route(Deliverable& msg, const string& routingKey, const FieldTable* /*args*/){ Monitor::ScopedLock l(lock); -- cgit v1.2.1