Go to the documentation of this file.00001
00022 #ifndef HYPERTABLE_COMMENGINE_H
00023 #define HYPERTABLE_COMMENGINE_H
00024
00025 #include "Common/Mutex.h"
00026 #include "Common/ReferenceCount.h"
00027
00028 #include "CommAddress.h"
00029 #include "CommBuf.h"
00030 #include "ConnectionHandlerFactory.h"
00031 #include "DispatchHandler.h"
00032 #include "HandlerMap.h"
00033
00034
00035 namespace Hypertable {
00036
00043 class Comm : public ReferenceCount {
00044 public:
00045 static Comm *instance() {
00046 ScopedLock lock(ms_mutex);
00047
00048 if (!ms_instance)
00049 ms_instance = new Comm();
00050
00051 return ms_instance;
00052 }
00053
00054 static void destroy();
00055
00067 int connect(const CommAddress &addr,
00068 DispatchHandlerPtr &default_handler);
00069
00082 int connect(const CommAddress &addr, const CommAddress &local_addr,
00083 DispatchHandlerPtr &default_handler);
00084
00085
00092 int set_alias(const InetAddr &addr, const InetAddr &alias);
00093
00100 int add_proxy(const String &proxy, const InetAddr &addr);
00101
00107 void get_proxy_map(ProxyMapT &proxy_map);
00108
00116 bool wait_for_proxy_load(Timer &timer);
00117
00129 void listen(const CommAddress &addr, ConnectionHandlerFactoryPtr &chf);
00130
00143 void listen(const CommAddress &addr, ConnectionHandlerFactoryPtr &chf,
00144 DispatchHandlerPtr &default_handler);
00145
00178 int send_request(const CommAddress &addr, uint32_t timeout_ms,
00179 CommBufPtr &cbuf, DispatchHandler *response_handler);
00180
00203 int send_response(const CommAddress &addr, CommBufPtr &cbuf);
00204
00214 int get_local_address(const CommAddress &addr, CommAddress &local_addr);
00215
00227 void create_datagram_receive_socket(CommAddress &addr, int tos,
00228 DispatchHandlerPtr &handler);
00229
00242 int send_datagram(const CommAddress &addr, const CommAddress &send_addr,
00243 CommBufPtr &cbuf);
00244
00256 int set_timer(uint32_t duration_millis, DispatchHandler *handler);
00257
00268 int set_timer_absolute(boost::xtime expire_time, DispatchHandler *handler);
00269
00279 int close_socket(const CommAddress &addr);
00280
00281 private:
00282 Comm();
00283 ~Comm();
00284
00285 static Comm *ms_instance;
00286
00287 int send_request(IOHandlerDataPtr &data_handler, uint32_t timeout_ms,
00288 CommBufPtr &cbuf, DispatchHandler *response_handler);
00289
00290 int connect_socket(int sd, const CommAddress &addr,
00291 DispatchHandlerPtr &default_handler);
00292
00293 static atomic_t ms_next_request_id;
00294
00295 static Mutex ms_mutex;
00296 HandlerMapPtr m_handler_map;
00297 ReactorPtr m_timer_reactor;
00298 };
00299
00300 }
00301
00302 #endif // HYPERTABLE_COMMENGINE_H