00001 #ifndef _broker_ExchangeRegistry_h
00002 #define _broker_ExchangeRegistry_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Exchange.h"
00026 #include "MessageStore.h"
00027 #include "qpid/framing/FieldTable.h"
00028 #include "qpid/sys/Monitor.h"
00029 #include "qpid/management/Manageable.h"
00030
00031 #include <boost/function.hpp>
00032 #include <boost/bind.hpp>
00033
00034 #include <algorithm>
00035 #include <map>
00036
00037 namespace qpid {
00038 namespace broker {
00039
00040 struct UnknownExchangeTypeException{};
00041
00042 class ExchangeRegistry{
00043 public:
00044 typedef boost::function4<Exchange::shared_ptr, const std::string&,
00045 bool, const qpid::framing::FieldTable&, qpid::management::Manageable*> FactoryFunction;
00046
00047 ExchangeRegistry () : parent(0) {}
00048 std::pair<Exchange::shared_ptr, bool> declare(const std::string& name, const std::string& type)
00049 throw(UnknownExchangeTypeException);
00050 std::pair<Exchange::shared_ptr, bool> declare(const std::string& name, const std::string& type,
00051 bool durable, const qpid::framing::FieldTable& args = framing::FieldTable())
00052 throw(UnknownExchangeTypeException);
00053 void destroy(const std::string& name);
00054 Exchange::shared_ptr get(const std::string& name);
00055 Exchange::shared_ptr getDefault();
00056
00060 void setParent (management::Manageable* _parent) { parent = _parent; }
00061
00065 bool registerExchange(const Exchange::shared_ptr&);
00066
00067 void registerType(const std::string& type, FactoryFunction);
00068
00070 template <class F> void eachExchange(F f) const {
00071 qpid::sys::RWlock::ScopedWlock l(lock);
00072 for (ExchangeMap::const_iterator i = exchanges.begin(); i != exchanges.end(); ++i)
00073 f(i->second);
00074 }
00075
00076 private:
00077 typedef std::map<std::string, Exchange::shared_ptr> ExchangeMap;
00078 typedef std::map<std::string, FactoryFunction > FunctionMap;
00079
00080 ExchangeMap exchanges;
00081 FunctionMap factory;
00082 mutable qpid::sys::RWlock lock;
00083 management::Manageable* parent;
00084
00085 };
00086
00087 }}
00088
00089
00090 #endif