zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups
client.hpp
1 #pragma once
2 
3 #include <zk/config.hpp>
4 
5 #include <memory>
6 #include <utility>
7 
8 #include "buffer.hpp"
9 #include "forwards.hpp"
10 #include "future.hpp"
11 #include "optional.hpp"
12 #include "string_view.hpp"
13 #include "results.hpp"
14 #include "types.hpp"
15 
16 namespace zk
17 {
18 
27 class client final
28 {
29 public:
30  client() noexcept;
31 
36  explicit client(string_view conn_string);
37 
39  explicit client(std::shared_ptr<connection> conn) noexcept;
40 
47  static future<client> connect(string_view conn_string);
48 
49  client(const client&) noexcept = default;
50  client(client&&) noexcept = default;
51 
52  client& operator=(const client&) noexcept = default;
53  client& operator=(client&&) noexcept = default;
54 
55  ~client() noexcept;
56 
57  void close();
58 
63  future<get_result> get(string_view path) const;
64 
72  future<watch_result> watch(string_view path) const;
73 
81  future<get_children_result> get_children(string_view path) const;
82 
87  future<watch_children_result> watch_children(string_view path) const;
88 
90  future<exists_result> exists(string_view path) const;
91 
96  future<watch_exists_result> watch_exists(string_view path) const;
97 
120  future<create_result> create(string_view path,
121  const buffer& data,
122  const acl& rules,
124  );
125  future<create_result> create(string_view path,
126  const buffer& data,
128  );
129 
140  future<set_result> set(string_view path, const buffer& data, version check = version::any());
141 
146  future<get_acl_result> get_acl(string_view path) const;
147 
158  future<void> set_acl(string_view path, const acl& rules, acl_version check = acl_version::any());
159 
172  future<void> erase(string_view path, version check = version::any());
173 
207  future<void> load_fence() const;
208 
218  future<multi_result> commit(multi_op txn);
219 
220 private:
221  std::shared_ptr<connection> _conn;
222 };
223 
226 }
Describes the various result types of client operations.
Controls the import of the optional and nullopt_t types, as well as the nullopt constexpr.
future< multi_result > commit(multi_op txn)
Commit the transaction specified by txn.
Definition: client.cpp:140
future< void > erase(string_view path, version check=version::any())
Erase the node with the given path.
Definition: client.cpp:130
Represents a version of the ACL of a ZNode.
Definition: types.hpp:145
future< watch_result > watch(string_view path) const
Similar to get, but if the call is successful (no error is returned), a watch will be left on the nod...
Definition: client.cpp:73
future< exists_result > exists(string_view path) const
Return the stat of the node of the given path or nullopt if no such node exists.
Definition: client.cpp:88
future< create_result > create(string_view path, const buffer &data, const acl &rules, create_mode mode=create_mode::normal)
Create a node with the given path.
Definition: client.cpp:98
create_mode
When used in client::set, this value determines how the znode is created on the server.
Definition: types.hpp:252
Standard behavior of a znode – the opposite of doing any of the options.
static future< client > connect(string_view conn_string)
Create a client connected to the cluster specified by conn_string.
Definition: client.cpp:24
future< void > load_fence() const
Ensure that all subsequent reads observe the data at the transaction on the server at or past real-ti...
Definition: client.cpp:135
Controls the import of future and promise types.
Controls the import of the string_view type.
future< get_acl_result > get_acl(string_view path) const
Return the ACL and stat of the node of the given path.
Definition: client.cpp:120
future< watch_children_result > watch_children(string_view path) const
Similar to get_children, but if the call is successful (no error is returned), a watch will be left o...
Definition: client.cpp:83
An access control list is a wrapper around acl_rule instances.
Definition: acl.hpp:124
Controls the buffer type.
future< watch_exists_result > watch_exists(string_view path) const
Similar to watch, but if the call is successful (no error is returned), a watch will be left on the n...
Definition: client.cpp:93
future< void > set_acl(string_view path, const acl &rules, acl_version check=acl_version::any())
Set the ACL for the node of the given path if such a node exists and the given version check matches ...
Definition: client.cpp:125
future< set_result > set(string_view path, const buffer &data, version check=version::any())
Set the data for the node of the given path if such a node exists and the given version matches the v...
Definition: client.cpp:115
static constexpr version any()
When specified in an operation, this version specifier will always pass.
Definition: types.hpp:122
future< get_children_result > get_children(string_view path) const
Return the list of the children of the node of the given path.
Definition: client.cpp:78
Represents a version of the data.
Definition: types.hpp:131
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:67
A ZooKeeper client connection.
Definition: client.hpp:27