00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _QPID_CONSOLE_BROKER_H_
00022 #define _QPID_CONSOLE_BROKER_H_
00023
00024 #include "qpid/console/ConsoleImportExport.h"
00025 #include "qpid/client/Connection.h"
00026 #include "qpid/client/ConnectionSettings.h"
00027 #include "qpid/client/SubscriptionManager.h"
00028 #include "qpid/client/Session.h"
00029 #include "qpid/client/AsyncSession.h"
00030 #include "qpid/client/Message.h"
00031 #include "qpid/client/MessageListener.h"
00032 #include "qpid/sys/Thread.h"
00033 #include "qpid/sys/Runnable.h"
00034 #include "qpid/sys/Mutex.h"
00035 #include "qpid/sys/Condition.h"
00036 #include "qpid/Url.h"
00037 #include "qpid/framing/Buffer.h"
00038 #include "qpid/framing/Uuid.h"
00039 #include <string>
00040 #include <iostream>
00041
00042 namespace qpid {
00043 namespace console {
00044 class SessionManager;
00045 class Agent;
00046 class Object;
00047
00052 class Broker : public client::MessageListener {
00053 public:
00054 QPID_CONSOLE_EXTERN Broker(SessionManager& sm,
00055 client::ConnectionSettings& settings);
00056 QPID_CONSOLE_EXTERN ~Broker();
00057
00058 bool isConnected() const { return connected; }
00059 const std::string& getError() const { return error; }
00060 const std::string& getSessionId() const { return amqpSessionId; }
00061 const framing::Uuid& getBrokerId() const { return brokerId; }
00062 uint32_t getBrokerBank() const { return 1; }
00063 void addBinding(const std::string& key) {
00064 connThreadBody.bindExchange("qpid.management", key);
00065 }
00066 QPID_CONSOLE_EXTERN std::string getUrl() const;
00067
00068 private:
00069 friend class SessionManager;
00070 friend class Object;
00071 typedef std::map<uint64_t,Agent*> AgentMap;
00072 static const int SYNC_TIME = 60;
00073
00074 SessionManager& sessionManager;
00075 AgentMap agents;
00076 bool connected;
00077 std::string error;
00078 std::string amqpSessionId;
00079 client::ConnectionSettings connectionSettings;
00080 sys::Mutex lock;
00081 sys::Condition cond;
00082 framing::Uuid brokerId;
00083 uint32_t reqsOutstanding;
00084 bool syncInFlight;
00085 bool topicBound;
00086 Object* methodObject;
00087
00088 friend class ConnectionThread;
00089 class ConnectionThread : public sys::Runnable {
00090 bool operational;
00091 bool shuttingDown;
00092 Broker& broker;
00093 framing::Uuid sessionId;
00094 client::Connection connection;
00095 client::Session session;
00096 client::SubscriptionManager* subscriptions;
00097 std::stringstream queueName;
00098 sys::Mutex connLock;
00099 void run();
00100 public:
00101 ConnectionThread(Broker& _broker) :
00102 operational(false), shuttingDown(false), broker(_broker), subscriptions(0) {}
00103 ~ConnectionThread();
00104 void sendBuffer(qpid::framing::Buffer& buf,
00105 uint32_t length,
00106 const std::string& exchange = "qpid.management",
00107 const std::string& routingKey = "broker");
00108 void bindExchange(const std::string& exchange, const std::string& key);
00109 void shutdown();
00110 };
00111
00112 ConnectionThread connThreadBody;
00113 sys::Thread connThread;
00114
00115 void encodeHeader(framing::Buffer& buf, uint8_t opcode, uint32_t seq = 0) const;
00116 bool checkHeader(framing::Buffer& buf, uint8_t *opcode, uint32_t *seq) const;
00117 void received(client::Message& msg);
00118 void resetAgents();
00119 void updateAgent(const Object& object);
00120 void waitForStable();
00121 void incOutstanding();
00122 void decOutstanding();
00123 void setBrokerId(const framing::Uuid& id) { brokerId = id; }
00124 void appendAgents(std::vector<Agent*>& agents) const;
00125
00126 friend QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Broker& k);
00127 };
00128
00129 QPID_CONSOLE_EXTERN std::ostream& operator<<(std::ostream& o, const Broker& k);
00130 }
00131 }
00132
00133 #endif