summaryrefslogtreecommitdiff
path: root/cpp/broker/inc/TopicExchange.h
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2006-09-21 18:26:31 +0000
committerAlan Conway <aconway@apache.org>2006-09-21 18:26:31 +0000
commit474ed3cf1e125360d26dad4376e106e8b48541ac (patch)
tree4f1043da7f03a5ec230539a62afac3fb0f0f0b73 /cpp/broker/inc/TopicExchange.h
parent82e07bb30905feb2c11bb6d9f3624f976ab070a5 (diff)
downloadqpid-python-474ed3cf1e125360d26dad4376e106e8b48541ac.tar.gz
Implemented topic pattern matching for the TopicExchange.
Corrected default bindings to use the exchange named "" rather than "amqp.direct". Added python and unit tests for all of the above. Minor improvements to testlib.py, also some tests for testlib itself. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@448624 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/broker/inc/TopicExchange.h')
-rw-r--r--cpp/broker/inc/TopicExchange.h71
1 files changed, 55 insertions, 16 deletions
diff --git a/cpp/broker/inc/TopicExchange.h b/cpp/broker/inc/TopicExchange.h
index d9ff62ecc6..68a4026ee7 100644
--- a/cpp/broker/inc/TopicExchange.h
+++ b/cpp/broker/inc/TopicExchange.h
@@ -18,7 +18,7 @@
#ifndef _TopicExchange_
#define _TopicExchange_
-#include <map>
+#include <tr1/unordered_map>
#include <vector>
#include "Exchange.h"
#include "FieldTable.h"
@@ -28,28 +28,67 @@
namespace qpid {
namespace broker {
- class TopicExchange : public virtual Exchange{
- const string name;
- std::map<string, std::vector<Queue::shared_ptr> > bindings;//NOTE: pattern matching not yet supported
- qpid::concurrent::MonitorImpl lock;
- public:
- static const std::string typeName;
-
- TopicExchange(const string& name);
+/** A vector of string tokens */
+class Tokens : public std::vector<std::string> {
+ public:
+ Tokens() {};
+ // Default copy, assign, dtor are sufficient.
+
+ /** Tokenize s, provides automatic conversion of string to Tokens */
+ Tokens(const std::string& s) { operator=(s); }
+ /** Tokenize s */
+ Tokens & operator=(const std::string& s);
+
+ struct Hash { size_t operator()(const Tokens&) const; };
+ typedef std::equal_to<Tokens> Equal;
+};
+
+/**
+ * Tokens that have been normalized as a pattern and can be matched
+ * with topic Tokens. Normalized meands all sequences of mixed * and
+ * # are reduced to a series of * followed by at most one #.
+ */
+class TopicPattern : public Tokens
+{
+ public:
+ TopicPattern() {}
+ // Default copy, assign, dtor are sufficient.
+ TopicPattern(const Tokens& tokens) { operator=(tokens); }
+ TopicPattern(const std::string& str) { operator=(str); }
+ TopicPattern& operator=(const Tokens&);
+ TopicPattern& operator=(const std::string& str) { operator=(Tokens(str)); }
+
+ /** Match a topic */
+ bool match(const std::string& topic) { return match(Tokens(topic)); }
+ bool match(const Tokens& topic) const;
+
+ private:
+ void normalize();
+};
+
+class TopicExchange : public virtual Exchange{
+ typedef std::tr1::unordered_map<TopicPattern, Queue::vector, TopicPattern::Hash> BindingMap;
+ BindingMap bindings;
+ qpid::concurrent::MonitorImpl lock;
+
+ public:
+ static const std::string typeName;
+
+ TopicExchange(const string& name);
- inline virtual const string& getName(){ return name; }
+ virtual void bind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args);
- virtual void bind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args);
+ virtual void unbind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args);
+
+ virtual void route(Message::shared_ptr& msg, const string& routingKey, qpid::framing::FieldTable* args);
+
+ virtual ~TopicExchange();
+};
- virtual void unbind(Queue::shared_ptr queue, const string& routingKey, qpid::framing::FieldTable* args);
- virtual void route(Message::shared_ptr& msg, const string& routingKey, qpid::framing::FieldTable* args);
- virtual ~TopicExchange();
- };
}
}
-
#endif