OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
zookeeper_client.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3 //
4 
5 #ifndef ZOOKEEPER_ZOOKEEPER_CLIENT_H_
6 #define ZOOKEEPER_ZOOKEEPER_CLIENT_H_
7 
8 #include <boost/function.hpp>
9 
10 class ZookeeperClientTest;
11 
12 namespace zookeeper {
13 namespace client {
14 
15 // Forward declarations
16 namespace impl {
17 class ZookeeperClientImpl;
18 } // namespace impl
19 
20 typedef enum Z_NODE_TYPE {
25 
26 typedef boost::function<void (void)> ZooStateCallback;
27 
28 //
29 // Blocking, synchronous, non-thread safe Zookeeper client
30 //
32  public:
33  ZookeeperClient(const char *hostname, const char *servers);
34  virtual ~ZookeeperClient();
35  bool CreateNode(const char *path,
36  const char *data,
38  bool CheckNodeExist(const char* path);
39  bool DeleteNode(const char* path);
40  void Shutdown();
43 
44  private:
46 
47  friend class ZookeeperLock;
48  friend class ::ZookeeperClientTest;
49 
50  std::unique_ptr<impl::ZookeeperClientImpl> impl_;
51 };
52 
53 //
54 // Usage is to first create a ZookeeperClient, and then ZookeeperLock
55 // for distributed synchronization
56 //
58  public:
59  ZookeeperLock(ZookeeperClient *client, const char *path);
60  virtual ~ZookeeperLock();
61 
62  bool Lock();
63  bool Release();
64 
65  private:
67  friend class ::ZookeeperClientTest;
68 
69  std::string Id() const;
70 
71  std::unique_ptr<ZookeeperLockImpl> impl_;
72 };
73 
74 } // namespace client
75 } // namespace zookeeper
76 
77 #endif // ZOOKEEPER_ZOOKEEPER_CLIENT_H_
ZookeeperLock(ZookeeperClient *client, const char *path)
bool CreateNode(const char *path, const char *data, int type=Z_NODE_TYPE_PERSISTENT)
bool CheckNodeExist(const char *path)
uint8_t type
Definition: load_balance.h:109
std::unique_ptr< ZookeeperLockImpl > impl_
void AddListener(ZooStateCallback cb)
boost::function< void(void)> ZooStateCallback
ZookeeperClient(const char *hostname, const char *servers)
enum zookeeper::client::Z_NODE_TYPE Z_NODE_TYPE_E
std::unique_ptr< impl::ZookeeperClientImpl > impl_