zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends 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 
22 
25 class client final
26 {
27 public:
29  client() noexcept;
30 
32  explicit client(const connection_params& params);
33 
37  explicit client(string_view conn_string);
38 
40  explicit client(std::shared_ptr<connection> conn) noexcept;
41 
48  static future<client> connect(string_view conn_string);
49  static future<client> connect(connection_params conn_params);
51 
52  client(const client&) noexcept = default;
53  client(client&&) noexcept = default;
54 
55  client& operator=(const client&) noexcept = default;
56  client& operator=(client&&) noexcept = default;
57 
58  ~client() noexcept;
59 
63  void close();
64 
68  future<get_result> get(string_view path) const;
69 
76  future<watch_result> watch(string_view path) const;
77 
84  future<get_children_result> get_children(string_view path) const;
85 
89  future<watch_children_result> watch_children(string_view path) const;
90 
92  future<exists_result> exists(string_view path) const;
93 
97  future<watch_exists_result> watch_exists(string_view path) const;
98 
122  future<create_result> create(string_view path,
123  const buffer& data,
124  const acl& rules,
126  );
127  future<create_result> create(string_view path,
128  const buffer& data,
130  );
132 
142  future<set_result> set(string_view path, const buffer& data, version check = version::any());
143 
147  future<get_acl_result> get_acl(string_view path) const;
148 
159  future<void> set_acl(string_view path, const acl& rules, acl_version check = acl_version::any());
160 
172  future<void> erase(string_view path, version check = version::any());
173 
206  future<void> load_fence() const;
207 
216  future<multi_result> commit(multi_op txn);
217 
218 private:
219  std::shared_ptr<connection> _conn;
220 };
221 
223 
224 }
Describes the various result types of client operations.
client() noexcept
Create a non-connected client. All operations will fail.
Imports of 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:149
future< void > erase(string_view path, version check=version::any())
Erase the entry at the given path.
Definition: client.cpp:139
Represents a version of the ACL of an entry.
Definition: types.hpp:171
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 ent...
Definition: client.cpp:82
future< exists_result > exists(string_view path) const
Return the stat of the entry of the given path or nullopt if it does not exist.
Definition: client.cpp:97
future< create_result > create(string_view path, const buffer &data, const acl &rules, create_mode mode=create_mode::normal)
Definition: client.cpp:107
create_mode
When used in client::set, this value determines how the entry is created on the server.
Definition: types.hpp:283
Standard behavior of an entry – the opposite of doing any of the options.
static future< client > connect(string_view conn_string)
Definition: client.cpp:28
void close()
Close the underlying connection.
Definition: client.cpp:72
Used to specify parameters for a connection.
Definition: connection.hpp:84
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:144
A collection of operations that will be performed atomically.
Definition: multi.hpp:162
Controls the import of future and promise types.
Imports the string_view type as std::string_view.
future< get_acl_result > get_acl(string_view path) const
Return the ACL and stat of the entry of the given path.
Definition: client.cpp:129
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:92
An access control list is a wrapper around acl_rule instances.
Definition: acl.hpp:139
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 e...
Definition: client.cpp:102
future< void > set_acl(string_view path, const acl &rules, acl_version check=acl_version::any())
Set the ACL for the entry of the given path if such an entry exists and the given version check match...
Definition: client.cpp:134
future< set_result > set(string_view path, const buffer &data, version check=version::any())
Set the data for the entry of the given path if such an entry exists and the given version matches th...
Definition: client.cpp:124
static constexpr version any()
When specified in an operation, this version specifier will always pass.
Definition: types.hpp:150
future< get_children_result > get_children(string_view path) const
Return the list of the children of the entry of the given path.
Definition: client.cpp:87
Represents a version of the data.
Definition: types.hpp:158
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:69
A ZooKeeper client connection.
Definition: client.hpp:25