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  explicit client(const connection_params& params);
30 
34  explicit client(string_view conn_string);
35 
37  explicit client(std::shared_ptr<connection> conn) noexcept;
38 
45  static future<client> connect(string_view conn_string);
46  static future<client> connect(connection_params conn_params);
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 
60  void close();
61 
65  future<get_result> get(string_view path) const;
66 
73  future<watch_result> watch(string_view path) const;
74 
81  future<get_children_result> get_children(string_view path) const;
82 
86  future<watch_children_result> watch_children(string_view path) const;
87 
89  future<exists_result> exists(string_view path) const;
90 
94  future<watch_exists_result> watch_exists(string_view path) const;
95 
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  );
129 
139  future<set_result> set(string_view path, const buffer& data, version check = version::any());
140 
144  future<get_acl_result> get_acl(string_view path) const;
145 
156  future<void> set_acl(string_view path, const acl& rules, acl_version check = acl_version::any());
157 
169  future<void> erase(string_view path, version check = version::any());
170 
203  future<void> load_fence() const;
204 
213  future<multi_result> commit(multi_op txn);
214 
215 private:
216  std::shared_ptr<connection> _conn;
217 };
218 
220 
221 }
Describes the various result types of client operations.
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
client(const connection_params &params)
Create a client connected to the cluster specified by params.
Definition: client.cpp:16
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:79
A ZooKeeper client connection.
Definition: client.hpp:25