zookeeper-cpp
ZooKeeper Client for C++
connection_zk.hpp
1 #pragma once
2 
3 #include <zk/config.hpp>
4 
5 #include <chrono>
6 
7 #include "connection.hpp"
8 #include "string_view.hpp"
9 
10 typedef struct _zhandle zhandle_t;
11 
12 namespace zk
13 {
14 
19 class connection_zk final :
20  public connection
21 {
22 public:
23  explicit connection_zk(string_view conn_string,
24  std::chrono::milliseconds recv_timeout = std::chrono::milliseconds(10000)
25  );
26 
27  virtual ~connection_zk() noexcept;
28 
29  virtual void close() override;
30 
31  virtual zk::state state() const override;
32 
33  virtual future<get_result> get(string_view path) override;
34 
35  virtual future<watch_result> watch(string_view path) override;
36 
37  virtual future<get_children_result> get_children(string_view path) override;
38 
39  virtual future<watch_children_result> watch_children(string_view path) override;
40 
41  virtual future<exists_result> exists(string_view path) override;
42 
43  virtual future<watch_exists_result> watch_exists(string_view path) override;
44 
45  virtual future<create_result> create(string_view path,
46  const buffer& data,
47  const acl& rules,
48  create_mode mode
49  ) override;
50 
51  virtual future<set_result> set(string_view path, const buffer& data, version check) override;
52 
53  virtual future<void> erase(string_view path, version check) override;
54 
55  virtual future<get_acl_result> get_acl(string_view path) const override;
56 
57  virtual future<void> set_acl(string_view path, const acl& rules, acl_version check) override;
58 
59  virtual future<multi_result> commit(multi_op&& txn) override;
60 
61  virtual future<void> load_fence() override;
62 
63 private:
64  static void on_session_event_raw(ptr<zhandle_t> handle,
65  int ev_type,
66  int state,
67  ptr<const char> path,
68  ptr<void> watcher_ctx
69  ) noexcept;
70 
71 private:
72  ptr<zhandle_t> _handle;
73 };
74 
77 }
T * ptr
A simple, unowned pointer.
Definition: config.hpp:75
state
Enumeration of states the client may be at when a watch triggers.
Definition: types.hpp:320
Definition: acl.cpp:8
Represents a version of the ACL of a ZNode.
Definition: types.hpp:145
create_mode
When used in client::set, this value determines how the znode is created on the server.
Definition: types.hpp:252
Controls the import of the string_view type.
An access control list is a wrapper around acl_rule instances.
Definition: acl.hpp:124
Represents a version of the data.
Definition: types.hpp:131
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:67