summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2008-07-14 13:22:35 +0000
committerGordon Sim <gsim@apache.org>2008-07-14 13:22:35 +0000
commit5dbc08285799e801719d01ced356e960c38ac57a (patch)
treecfc4b5fabcc560d4a3a33b5b776f35fd772dc728
parent13ba086a8edc90d5e0d415e5116d748cec459822 (diff)
downloadqpid-python-5dbc08285799e801719d01ced356e960c38ac57a.tar.gz
Allow for pluggable exchange types.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-10@676581 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--cpp/src/qpid/broker/ExchangeRegistry.cpp13
-rw-r--r--cpp/src/qpid/broker/ExchangeRegistry.h21
2 files changed, 28 insertions, 6 deletions
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<Exchange::shared_ptr, bool> 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::shared_ptr, bool>(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 <map>
+#include <boost/function.hpp>
#include "Exchange.h"
#include "MessageStore.h"
#include "qpid/framing/FieldTable.h"
@@ -34,11 +35,10 @@ namespace broker {
struct UnknownExchangeTypeException{};
class ExchangeRegistry{
- typedef std::map<std::string, Exchange::shared_ptr> ExchangeMap;
- ExchangeMap exchanges;
- qpid::sys::RWlock lock;
- management::Manageable* parent;
public:
+ typedef boost::function4<Exchange::shared_ptr, const std::string&,
+ bool, const qpid::framing::FieldTable&, qpid::management::Manageable*> FactoryFunction;
+
ExchangeRegistry () : parent(0) {}
std::pair<Exchange::shared_ptr, bool> 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<std::string, Exchange::shared_ptr> ExchangeMap;
+ typedef std::map<std::string, FactoryFunction > FunctionMap;
+
+ ExchangeMap exchanges;
+ FunctionMap factory;
+ qpid::sys::RWlock lock;
+ management::Manageable* parent;
+
};
}
}