You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2008/07/09 18:52:20 UTC
svn commit: r675252 - in /incubator/qpid/trunk/qpid/cpp/src/qpid/broker:
ExchangeRegistry.cpp ExchangeRegistry.h
Author: gsim
Date: Wed Jul 9 09:52:20 2008
New Revision: 675252
URL: http://svn.apache.org/viewvc?rev=675252&view=rev
Log:
Allow for pluggable exchange types.
Modified:
incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.h
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.cpp?rev=675252&r1=675251&r2=675252&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.cpp Wed Jul 9 09:52:20 2008
@@ -67,7 +67,12 @@
}
#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 @@
return i->second;
}
+void ExchangeRegistry::registerType(const std::string& type, FactoryFunction f)
+{
+ factory[type] = f;
+}
+
+
namespace
{
const std::string empty;
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.h?rev=675252&r1=675251&r2=675252&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/ExchangeRegistry.h Wed Jul 9 09:52:20 2008
@@ -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 @@
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 @@
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;
+
};
}
}