zookeeper-cpp
ZooKeeper Client for C++
connection.hpp
1 #pragma once
2 
3 #include <zk/config.hpp>
4 
5 #include <memory>
6 #include <mutex>
7 #include <vector>
8 
9 #include "buffer.hpp"
10 #include "forwards.hpp"
11 #include "future.hpp"
12 #include "string_view.hpp"
13 
14 namespace zk
15 {
16 
22 {
23 public:
24  static std::shared_ptr<connection> connect(string_view conn_string);
25 
26  virtual ~connection() noexcept;
27 
28  virtual void close() = 0;
29 
30  virtual future<get_result> get(string_view path) = 0;
31 
32  virtual future<watch_result> watch(string_view path) = 0;
33 
34  virtual future<get_children_result> get_children(string_view path) = 0;
35 
36  virtual future<watch_children_result> watch_children(string_view path) = 0;
37 
38  virtual future<exists_result> exists(string_view path) = 0;
39 
40  virtual future<watch_exists_result> watch_exists(string_view path) = 0;
41 
42  virtual future<create_result> create(string_view path,
43  const buffer& data,
44  const acl& rules,
45  create_mode mode
46  ) = 0;
47 
48  virtual future<set_result> set(string_view path, const buffer& data, version check) = 0;
49 
50  virtual future<void> erase(string_view path, version check) = 0;
51 
52  virtual future<get_acl_result> get_acl(string_view path) const = 0;
53 
54  virtual future<void> set_acl(string_view path, const acl& rules, acl_version check) = 0;
55 
56  virtual future<multi_result> commit(multi_op&& txn) = 0;
57 
58  virtual future<void> load_fence() = 0;
59 
60  virtual zk::state state() const = 0;
61 
63  virtual future<zk::state> watch_state();
64 
65 protected:
69  virtual void on_session_event(zk::state new_state);
70 
71 private:
72  mutable std::mutex _state_change_promises_protect;
73  std::vector<promise<zk::state>> _state_change_promises;
74 };
75 
78 }
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 future and promise types.
virtual future< zk::state > watch_state()
Watch for a state change.
Definition: connection.cpp:19
Controls the import of the string_view type.
An access control list is a wrapper around acl_rule instances.
Definition: acl.hpp:124
Controls the buffer type.
virtual void on_session_event(zk::state new_state)
Call this from derived classes when a session event happens.
Definition: connection.cpp:26
Represents a version of the data.
Definition: types.hpp:131
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:67