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/management/Manageable.h"
00032 #include "qpid/management/Exchange.h"
00033 #include "qpid/management/Binding.h"
00034
00035 namespace qpid {
00036 namespace broker {
00037 using std::string;
00038 class ExchangeRegistry;
00039
00040 class Exchange : public PersistableExchange, public management::Manageable {
00041 private:
00042 const string name;
00043 const bool durable;
00044 qpid::framing::FieldTable args;
00045 boost::shared_ptr<Exchange> alternate;
00046 uint32_t alternateUsers;
00047 mutable uint64_t persistenceId;
00048
00049 protected:
00050 struct Binding : public management::Manageable {
00051 typedef boost::shared_ptr<Binding> shared_ptr;
00052 typedef std::vector<Binding::shared_ptr> vector;
00053
00054 Queue::shared_ptr queue;
00055 const std::string key;
00056 const framing::FieldTable args;
00057 management::Binding::shared_ptr mgmtBinding;
00058
00059 Binding(const std::string& key, const Queue::shared_ptr queue, Exchange* parent = 0,
00060 framing::FieldTable args = framing::FieldTable ());
00061 ~Binding ();
00062 management::ManagementObject::shared_ptr GetManagementObject () const;
00063 management::Manageable::status_t ManagementMethod (uint32_t methodId, management::Args& args);
00064 };
00065
00066 management::Exchange::shared_ptr mgmtExchange;
00067
00068 public:
00069 typedef boost::shared_ptr<Exchange> shared_ptr;
00070
00071 explicit Exchange(const string& name, management::Manageable* parent = 0);
00072 Exchange(const string& _name, bool _durable, const qpid::framing::FieldTable& _args,
00073 management::Manageable* parent = 0);
00074 virtual ~Exchange();
00075
00076 const string& getName() const { return name; }
00077 bool isDurable() { return durable; }
00078 qpid::framing::FieldTable& getArgs() { return args; }
00079
00080 Exchange::shared_ptr getAlternate() { return alternate; }
00081 void setAlternate(Exchange::shared_ptr _alternate) { alternate = _alternate; }
00082 void incAlternateUsers() { alternateUsers++; }
00083 void decAlternateUsers() { alternateUsers--; }
00084 bool inUseAsAlternate() { return alternateUsers > 0; }
00085
00086 virtual string getType() const = 0;
00087 virtual bool bind(Queue::shared_ptr queue, const string& routingKey, const qpid::framing::FieldTable* args) = 0;
00088 virtual bool unbind(Queue::shared_ptr queue, const string& routingKey, const qpid::framing::FieldTable* args) = 0;
00089 virtual bool isBound(Queue::shared_ptr queue, const string* const routingKey, const qpid::framing::FieldTable* const args) = 0;
00090 virtual void route(Deliverable& msg, const string& routingKey, const qpid::framing::FieldTable* args) = 0;
00091
00092
00093 void setPersistenceId(uint64_t id) const;
00094 uint64_t getPersistenceId() const { return persistenceId; }
00095 uint32_t encodedSize() const;
00096 void encode(framing::Buffer& buffer) const;
00097
00098 static Exchange::shared_ptr decode(ExchangeRegistry& exchanges, framing::Buffer& buffer);
00099
00100
00101 management::ManagementObject::shared_ptr GetManagementObject (void) const;
00102 management::Manageable::status_t
00103 ManagementMethod (uint32_t, management::Args&) { return management::Manageable::STATUS_UNKNOWN_METHOD; }
00104 };
00105 }
00106 }
00107
00108
00109 #endif