00001 #ifndef _broker_Exchange_h
00002 #define _broker_Exchange_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 <boost/shared_ptr.hpp>
00026 #include "Deliverable.h"
00027 #include "Queue.h"
00028 #include "MessageStore.h"
00029 #include "PersistableExchange.h"
00030 #include "qpid/framing/FieldTable.h"
00031 #include "qpid/sys/Mutex.h"
00032 #include "qpid/management/Manageable.h"
00033 #include "qmf/org/apache/qpid/broker/Exchange.h"
00034 #include "qmf/org/apache/qpid/broker/Binding.h"
00035
00036 namespace qpid {
00037 namespace broker {
00038 using std::string;
00039 class ExchangeRegistry;
00040
00041 class Exchange : public PersistableExchange, public management::Manageable {
00042 private:
00043 const string name;
00044 const bool durable;
00045 qpid::framing::FieldTable args;
00046 boost::shared_ptr<Exchange> alternate;
00047 uint32_t alternateUsers;
00048 mutable uint64_t persistenceId;
00049
00050 protected:
00051 bool sequence;
00052 mutable qpid::sys::Mutex sequenceLock;
00053 uint64_t sequenceNo;
00054
00055 class PreRoute{
00056 public:
00057 PreRoute(Deliverable& msg, Exchange* _p);
00058 ~PreRoute();
00059 private:
00060 Exchange* parent;
00061 };
00062
00063 struct Binding : public management::Manageable {
00064 typedef boost::shared_ptr<Binding> shared_ptr;
00065 typedef std::vector<Binding::shared_ptr> vector;
00066
00067 Queue::shared_ptr queue;
00068 const std::string key;
00069 const framing::FieldTable args;
00070 qmf::org::apache::qpid::broker::Binding* mgmtBinding;
00071
00072 Binding(const std::string& key, Queue::shared_ptr queue, Exchange* parent = 0,
00073 framing::FieldTable args = framing::FieldTable ());
00074 ~Binding ();
00075 management::ManagementObject* GetManagementObject () const;
00076 };
00077 struct MatchQueue
00078 {
00079 const Queue::shared_ptr queue;
00080 MatchQueue(Queue::shared_ptr q);
00081 bool operator()(Exchange::Binding::shared_ptr b);
00082 };
00083
00084 qmf::org::apache::qpid::broker::Exchange* mgmtExchange;
00085
00086 public:
00087 typedef boost::shared_ptr<Exchange> shared_ptr;
00088
00089 explicit Exchange(const string& name, management::Manageable* parent = 0);
00090 Exchange(const string& _name, bool _durable, const qpid::framing::FieldTable& _args,
00091 management::Manageable* parent = 0);
00092 virtual ~Exchange();
00093
00094 const string& getName() const { return name; }
00095 bool isDurable() { return durable; }
00096 qpid::framing::FieldTable& getArgs() { return args; }
00097
00098 Exchange::shared_ptr getAlternate() { return alternate; }
00099 void setAlternate(Exchange::shared_ptr _alternate) { alternate = _alternate; }
00100 void incAlternateUsers() { alternateUsers++; }
00101 void decAlternateUsers() { alternateUsers--; }
00102 bool inUseAsAlternate() { return alternateUsers > 0; }
00103
00104 virtual string getType() const = 0;
00105 virtual bool bind(Queue::shared_ptr queue, const string& routingKey, const qpid::framing::FieldTable* args) = 0;
00106 virtual bool unbind(Queue::shared_ptr queue, const string& routingKey, const qpid::framing::FieldTable* args) = 0;
00107 virtual bool isBound(Queue::shared_ptr queue, const string* const routingKey, const qpid::framing::FieldTable* const args) = 0;
00108 virtual void route(Deliverable& msg, const string& routingKey, const qpid::framing::FieldTable* args) = 0;
00109
00110
00111 void setPersistenceId(uint64_t id) const;
00112 uint64_t getPersistenceId() const { return persistenceId; }
00113 uint32_t encodedSize() const;
00114 void encode(framing::Buffer& buffer) const;
00115
00116 static Exchange::shared_ptr decode(ExchangeRegistry& exchanges, framing::Buffer& buffer);
00117
00118
00119 management::ManagementObject* GetManagementObject(void) const;
00120 };
00121 }
00122 }
00123
00124
00125 #endif