/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/broker/TopicExchange.h

00001 /*
00002  *
00003  * Licensed to the Apache Software Foundation (ASF) under one
00004  * or more contributor license agreements.  See the NOTICE file
00005  * distributed with this work for additional information
00006  * regarding copyright ownership.  The ASF licenses this file
00007  * to you under the Apache License, Version 2.0 (the
00008  * "License"); you may not use this file except in compliance
00009  * with the License.  You may obtain a copy of the License at
00010  * 
00011  *   http://www.apache.org/licenses/LICENSE-2.0
00012  * 
00013  * Unless required by applicable law or agreed to in writing,
00014  * software distributed under the License is distributed on an
00015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00016  * KIND, either express or implied.  See the License for the
00017  * specific language governing permissions and limitations
00018  * under the License.
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     // Default copy, assign, dtor are sufficient.
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     // Default copy, assign, dtor are sufficient.
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

Generated on Thu Apr 10 11:08:17 2008 for Qpid by  doxygen 1.4.7