From 9575428feb2a81323f0426361830bc543eba29db Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Wed, 9 Jul 2008 16:52:20 +0000 Subject: Allow for pluggable exchange types. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@675252 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/broker/ExchangeRegistry.cpp | 13 ++++++++++++- cpp/src/qpid/broker/ExchangeRegistry.h | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'cpp') diff --git a/cpp/src/qpid/broker/ExchangeRegistry.cpp b/cpp/src/qpid/broker/ExchangeRegistry.cpp index c1eb5ff5a3..45eb308680 100644 --- a/cpp/src/qpid/broker/ExchangeRegistry.cpp +++ b/cpp/src/qpid/broker/ExchangeRegistry.cpp @@ -67,7 +67,12 @@ pair ExchangeRegistry::declare(const string& name, c } #endif else{ - throw UnknownExchangeTypeException(); + FunctionMap::iterator i = factory.find(type); + if (i == factory.end()) { + throw UnknownExchangeTypeException(); + } else { + exchange = i->second(name, durable, args, parent); + } } exchanges[name] = exchange; return std::pair(exchange, true); @@ -92,6 +97,12 @@ Exchange::shared_ptr ExchangeRegistry::get(const string& name){ return i->second; } +void ExchangeRegistry::registerType(const std::string& type, FactoryFunction f) +{ + factory[type] = f; +} + + namespace { const std::string empty; diff --git a/cpp/src/qpid/broker/ExchangeRegistry.h b/cpp/src/qpid/broker/ExchangeRegistry.h index f39bd661fa..7573e3e415 100644 --- a/cpp/src/qpid/broker/ExchangeRegistry.h +++ b/cpp/src/qpid/broker/ExchangeRegistry.h @@ -23,6 +23,7 @@ */ #include +#include #include "Exchange.h" #include "MessageStore.h" #include "qpid/framing/FieldTable.h" @@ -34,11 +35,10 @@ namespace broker { struct UnknownExchangeTypeException{}; class ExchangeRegistry{ - typedef std::map ExchangeMap; - ExchangeMap exchanges; - qpid::sys::RWlock lock; - management::Manageable* parent; public: + typedef boost::function4 FactoryFunction; + ExchangeRegistry () : parent(0) {} std::pair declare(const std::string& name, const std::string& type) throw(UnknownExchangeTypeException); @@ -50,9 +50,20 @@ namespace broker { Exchange::shared_ptr getDefault(); /** - * Register the manageable parent for declared queues + * Register the manageable parent for declared exchanges */ void setParent (management::Manageable* _parent) { parent = _parent; } + + void registerType(const std::string& type, FactoryFunction); + private: + typedef std::map ExchangeMap; + typedef std::map FunctionMap; + + ExchangeMap exchanges; + FunctionMap factory; + qpid::sys::RWlock lock; + management::Manageable* parent; + }; } } -- cgit v1.2.1