Line data Source code
1 : // 2 : // Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. 3 : // 4 : 5 : #ifndef ZOOKEEPER_ZOOKEEPER_CLIENT_IMPL_H_ 6 : #define ZOOKEEPER_ZOOKEEPER_CLIENT_IMPL_H_ 7 : 8 : #include <zookeeper/zookeeper.h> 9 : 10 : #include <zookeeper/zookeeper_interface.h> 11 : 12 : namespace zookeeper { 13 : namespace client { 14 : namespace impl { 15 : 16 : // 17 : // Blocking, synchronous, non-thread safe Zookeeper client 18 : // 19 : class ZookeeperClientImpl { 20 : public: 21 : ZookeeperClientImpl(const char *hostname, const char *servers, 22 : zookeeper::interface::ZookeeperInterface *zki); 23 : virtual ~ZookeeperClientImpl(); 24 : 25 : bool Connect(); 26 : void Shutdown(); 27 : bool Reconnect(); 28 : bool IsConnected() const; 29 : bool CreateNode(const char *path, const char *value, int flag); 30 : bool DeleteNode(const char *path); 31 : int CreateNodeSync(const char *path, const char *value, int *err, int flag); 32 : int GetNodeDataSync(const char *path, char *buf, int *buf_len, int *err); 33 : int DeleteNodeSync(const char *path, int *err); 34 : bool CheckNodeExist(const char *path); 35 0 : void SetClient(void *client) {client_ = client;} 36 0 : void *GetClient() {return client_;} 37 : std::string Name() const; 38 : 39 : private: 40 : static const int kSessionTimeoutMSec_ = 60000; 41 : 42 : std::string hostname_; 43 : std::string servers_; 44 : zhandle_t *zk_handle_; 45 : bool connected_; 46 : void *client_; 47 : std::unique_ptr<zookeeper::interface::ZookeeperInterface> zki_; 48 : }; 49 : 50 : } // namespace impl 51 : } // namespace client 52 : } // namespace zookeeper 53 : 54 : #endif // ZOOKEEPER_ZOOKEEPER_CLIENT_IMPL_H_