zookeeper-cpp
ZooKeeper Client for C++
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 
35  explicit client(string_view conn_string);
36 
38  explicit client(std::shared_ptr<connection> conn) noexcept;
39 
46  static future<client> connect(string_view conn_string);
47 
48  client(const client&) noexcept = default;
49  client(client&&) noexcept = default;
50 
51  client& operator=(const client&) noexcept = default;
52  client& operator=(client&&) noexcept = default;
53 
54  ~client() noexcept;
55 
56  void close();
57 
62  future<get_result> get(string_view path) const;
63 
71  future<watch_result> watch(string_view path) const;
72 
80  future<get_children_result> get_children(string_view path) const;
81 
86  future<watch_children_result> watch_children(string_view path) const;
87 
89  future<exists_result> exists(string_view path) const;
90 
95  future<watch_exists_result> watch_exists(string_view path) const;
96 
119  future<create_result> create(string_view path,
120  const buffer& data,
121  const acl& rules,
123  );
124  future<create_result> create(string_view path,
125  const buffer& data,
127  );
128 
139  future<set_result> set(string_view path, const buffer& data, version check = version::any());
140 
145  future<get_acl_result> get_acl(string_view path) const;
146 
157  future<void> set_acl(string_view path, const acl& rules, acl_version check = acl_version::any());
158 
171  future<void> erase(string_view path, version check = version::any());
172 
206  future<void> load_fence() const;
207 
217  future<multi_result> commit(multi_op txn);
218 
219 private:
220  std::shared_ptr<connection> _conn;
221 };
222 
225 }
Describes the various result types of client operations.
Definition: acl.cpp:8
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
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