zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups
connection_zk.hpp
1 #pragma once
2 
3 #include <zk/config.hpp>
4 
5 #include <chrono>
6 #include <memory>
7 #include <mutex>
8 #include <unordered_map>
9 
10 #include "connection.hpp"
11 #include "string_view.hpp"
12 
13 typedef struct _zhandle zhandle_t;
14 
15 namespace zk
16 {
17 
22 class connection_zk final :
23  public connection
24 {
25 public:
26  explicit connection_zk(const connection_params& params);
27 
28  virtual ~connection_zk() noexcept;
29 
30  virtual void close() override;
31 
32  virtual zk::state state() const override;
33 
34  virtual future<get_result> get(string_view path) override;
35 
36  virtual future<watch_result> watch(string_view path) override;
37 
38  virtual future<get_children_result> get_children(string_view path) override;
39 
40  virtual future<watch_children_result> watch_children(string_view path) override;
41 
42  virtual future<exists_result> exists(string_view path) override;
43 
44  virtual future<watch_exists_result> watch_exists(string_view path) override;
45 
46  virtual future<create_result> create(string_view path,
47  const buffer& data,
48  const acl& rules,
49  create_mode mode
50  ) override;
51 
52  virtual future<set_result> set(string_view path, const buffer& data, version check) override;
53 
54  virtual future<void> erase(string_view path, version check) override;
55 
56  virtual future<get_acl_result> get_acl(string_view path) const override;
57 
58  virtual future<void> set_acl(string_view path, const acl& rules, acl_version check) override;
59 
60  virtual future<multi_result> commit(multi_op&& txn) override;
61 
62  virtual future<void> load_fence() override;
63 
64 private:
65  static void on_session_event_raw(ptr<zhandle_t> handle,
66  int ev_type,
67  int state,
68  ptr<const char> path,
69  ptr<void> watcher_ctx
70  ) noexcept;
71 
72  using watch_function = void (*)(ptr<zhandle_t>, int type_in, int state_in, ptr<const char>, ptr<void>);
73 
74  class watcher;
75 
76  template <typename TResult>
77  class basic_watcher;
78 
79  class data_watcher;
80 
81  class child_watcher;
82 
83  class exists_watcher;
84 
89  std::shared_ptr<watcher> try_extract_watch(ptr<const void> p);
90 
91  static void deliver_watch(ptr<zhandle_t> zh, int type_in, int state_in, ptr<const char>, ptr<void> proms_in);
92 
93 private:
94  ptr<zhandle_t> _handle;
95  std::unordered_map<ptr<const void>, std::shared_ptr<watcher>> _watches;
96  mutable std::mutex _watches_protect;
97 };
98 
101 }
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
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
Used to specify parameters for a connection.
Definition: connection.hpp:84
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