00001 #ifndef _broker_Link_h
00002 #define _broker_Link_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 "MessageStore.h"
00027 #include "PersistableConfig.h"
00028 #include "Bridge.h"
00029 #include "qpid/sys/Mutex.h"
00030 #include "qpid/framing/FieldTable.h"
00031 #include "qpid/management/Manageable.h"
00032 #include "qmf/org/apache/qpid/broker/Link.h"
00033 #include <boost/ptr_container/ptr_vector.hpp>
00034
00035 namespace qpid {
00036 namespace broker {
00037
00038 using std::string;
00039 class LinkRegistry;
00040 class Broker;
00041 class Connection;
00042
00043 class Link : public PersistableConfig, public management::Manageable {
00044 private:
00045 sys::Mutex lock;
00046 LinkRegistry* links;
00047 MessageStore* store;
00048 string host;
00049 uint16_t port;
00050 string transport;
00051 bool durable;
00052 string authMechanism;
00053 string username;
00054 string password;
00055 mutable uint64_t persistenceId;
00056 qmf::org::apache::qpid::broker::Link* mgmtObject;
00057 Broker* broker;
00058 int state;
00059 uint32_t visitCount;
00060 uint32_t currentInterval;
00061 bool closing;
00062
00063 typedef std::vector<Bridge::shared_ptr> Bridges;
00064 Bridges created;
00065 Bridges active;
00066 uint channelCounter;
00067 Connection* connection;
00068
00069 static const int STATE_WAITING = 1;
00070 static const int STATE_CONNECTING = 2;
00071 static const int STATE_OPERATIONAL = 3;
00072 static const int STATE_FAILED = 4;
00073 static const int STATE_CLOSED = 5;
00074
00075 static const uint32_t MAX_INTERVAL = 32;
00076
00077 void setStateLH (int newState);
00078 void startConnectionLH();
00079 void destroy();
00080 void ioThreadProcessing();
00081
00082 public:
00083 typedef boost::shared_ptr<Link> shared_ptr;
00084
00085 Link(LinkRegistry* links,
00086 MessageStore* store,
00087 string& host,
00088 uint16_t port,
00089 string& transport,
00090 bool durable,
00091 string& authMechanism,
00092 string& username,
00093 string& password,
00094 Broker* broker,
00095 management::Manageable* parent = 0);
00096 virtual ~Link();
00097
00098 std::string getHost() { return host; }
00099 uint16_t getPort() { return port; }
00100 bool isDurable() { return durable; }
00101 void maintenanceVisit ();
00102 uint nextChannel();
00103 void add(Bridge::shared_ptr);
00104 void cancel(Bridge::shared_ptr);
00105
00106 void established();
00107 void closed(int, std::string);
00108 void setConnection(Connection*);
00109
00110 string getAuthMechanism() { return authMechanism; }
00111 string getUsername() { return username; }
00112 string getPassword() { return password; }
00113 Broker* getBroker() { return broker; }
00114
00115 void notifyConnectionForced(const std::string text);
00116
00117
00118 void setPersistenceId(uint64_t id) const;
00119 uint64_t getPersistenceId() const { return persistenceId; }
00120 uint32_t encodedSize() const;
00121 void encode(framing::Buffer& buffer) const;
00122 const string& getName() const;
00123
00124 static Link::shared_ptr decode(LinkRegistry& links, framing::Buffer& buffer);
00125
00126
00127 management::ManagementObject* GetManagementObject(void) const;
00128 management::Manageable::status_t ManagementMethod(uint32_t, management::Args&, std::string&);
00129 };
00130 }
00131 }
00132
00133
00134 #endif