00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _TopicExchange_
00022 #define _TopicExchange_
00023
00024 #include <map>
00025 #include <vector>
00026 #include "Exchange.h"
00027 #include "qpid/framing/FieldTable.h"
00028 #include "qpid/sys/Monitor.h"
00029 #include "Queue.h"
00030
00031 namespace qpid {
00032 namespace broker {
00033
00035 class Tokens : public std::vector<std::string> {
00036 public:
00037 Tokens() {};
00038
00039
00041 Tokens(const std::string& s) { operator=(s); }
00043 Tokens & operator=(const std::string& s);
00044
00045 private:
00046 size_t hash;
00047 };
00048
00049
00055 class TopicPattern : public Tokens
00056 {
00057 public:
00058 TopicPattern() {}
00059
00060 TopicPattern(const Tokens& tokens) { operator=(tokens); }
00061 TopicPattern(const std::string& str) { operator=(str); }
00062 TopicPattern& operator=(const Tokens&);
00063 TopicPattern& operator=(const std::string& str) { return operator=(Tokens(str)); }
00064
00066 bool match(const std::string& topic) { return match(Tokens(topic)); }
00067 bool match(const Tokens& topic) const;
00068
00069 private:
00070 void normalize();
00071 };
00072
00073 class TopicExchange : public virtual Exchange{
00074 typedef std::map<TopicPattern, Binding::vector> BindingMap;
00075 BindingMap bindings;
00076 qpid::sys::RWlock lock;
00077
00078 bool isBound(Queue::shared_ptr queue, TopicPattern& pattern);
00079 public:
00080 static const std::string typeName;
00081
00082 TopicExchange(const string& name, management::Manageable* parent = 0);
00083 TopicExchange(const string& _name, bool _durable,
00084 const qpid::framing::FieldTable& _args, management::Manageable* parent = 0);
00085
00086 virtual std::string getType() const { return typeName; }
00087
00088 virtual bool bind(Queue::shared_ptr queue, const string& routingKey, const qpid::framing::FieldTable* args);
00089
00090 virtual bool unbind(Queue::shared_ptr queue, const string& routingKey, const qpid::framing::FieldTable* args);
00091
00092 virtual void route(Deliverable& msg, const string& routingKey, const qpid::framing::FieldTable* args);
00093
00094 virtual bool isBound(Queue::shared_ptr queue, const string* const routingKey, const qpid::framing::FieldTable* const args);
00095
00096 virtual ~TopicExchange();
00097 };
00098
00099
00100
00101 }
00102 }
00103
00104 #endif