3 #ifndef ZKWRAPPER_INCLUDE_ZKWRAPPER_H_
4 #define ZKWRAPPER_INCLUDE_ZKWRAPPER_H_
7 #include <easylogging++.h>
23 ZKWRAPPERINSUFFICIENTBUFFER = -997,
24 ZKWRAPPERUNINITIALIZED = -998,
25 ZKWRAPPERDEFAULTERROR = -999
36 ZooOp(
const std::string &path_in,
37 const std::vector<std::uint8_t> &data_in) {
38 this->path =
new char[path_in.size() + 1];
39 snprintf(this->path, path_in.size() + 1,
"%s", path_in.c_str());
40 if (data_in.size() != 0) {
41 this->num_bytes = data_in.size();
42 this->data =
new char[this->num_bytes];
43 memcpy(this->data, data_in.data(), data_in.size());
56 zoo_op_t *op =
nullptr;
76 ZKWrapper(
const std::string &host,
int &error_code,
const std::string &root);
87 std::string removeZKRoot(
const std::string &path)
const;
89 std::string removeZKRootAndDir(
const std::string &prefix,
90 const std::string &path)
const;
100 static std::string translate_watch_event_type(
int type);
102 static std::string translate_watch_state(
int state);
104 static void watcher_znode_data(zhandle_t *zzh,
119 bool create(
const std::string &path,
120 const std::vector<std::uint8_t> &data,
123 bool sync =
true)
const;
125 bool create_ephemeral(
const std::string &path,
126 const std::vector<std::uint8_t> &data,
128 bool sync =
true)
const;
145 const std::vector<std::uint8_t> &data,
146 std::string &new_path,
149 bool sync =
true)
const;
162 const std::vector<std::uint8_t> &data,
164 bool sync =
true)
const;
176 bool exists(
const std::string &path,
bool &exist,
int &error_code)
const;
192 bool wexists(
const std::string &path,
196 int &error_code)
const;
208 bool sync =
true)
const;
233 std::vector<std::string> &children,
234 int &error_code)
const;
252 std::vector<std::string> &children,
255 int &error_code)
const;
276 bool get(
const std::string &path,
277 std::vector<std::uint8_t> &data,
290 bool get_info(
const std::string &path,
292 int &error_code)
const;
313 bool wget(
const std::string &path,
314 std::vector<std::uint8_t> &data,
330 bool set(
const std::string &path,
331 const std::vector<std::uint8_t> &data,
334 int version = -1)
const;
346 const std::vector<std::uint8_t> &data,
347 const int flags = 0)
const;
356 int version = -1)
const;
364 std::shared_ptr<ZooOp>
build_set_op(
const std::string &path,
365 const std::vector<std::uint8_t> &data,
366 int version = -1)
const;
380 bool execute_multi(
const std::vector<std::shared_ptr<ZooOp>> operations,
381 std::vector<zoo_op_result> &results,
383 bool sync =
true)
const;
392 bool flush(
const std::string &full_path,
bool synchronous =
false)
const;
396 static std::vector<uint8_t> get_byte_vector(
const std::string &
string);
398 static void print_error(
int error) {
402 static const std::vector<std::uint8_t> EMPTY_VECTOR;
405 friend void watcher(zhandle_t *zzh,
int type,
int state,
const char *path,
410 std::string root =
"";
417 bool connected =
false;
423 bool initializing =
true;
424 bool initialized =
false;
426 static const int MAX_PAYLOAD;
427 static const int MAX_PATH_LEN;
428 static const int NUM_SEQUENTIAL_DIGITS;
429 static const int DEFAULT_ZK_RECV_TIMEOUT;
430 static const int INITIAL_CONNECTION_TIMEOUT_MILLIS;
431 static const int INITIAL_CONNECTION_RETRY_INTERVAL_MILLIS;
432 static const int ROOT_CREATION_RETRY_LIMIT;
433 static const int ROOT_CREATION_RETRY_INTERVAL_MILLIS;
440 static const std::string CLASS_NAME;
443 #endif // ZKWRAPPER_INCLUDE_ZKWRAPPER_H_
Definition: LRUCache.h:209
std::shared_ptr< ZooOp > build_delete_op(const std::string &path, int version=-1) const
Definition: zkwrapper.cc:723
bool set(const std::string &path, const std::vector< std::uint8_t > &data, int &error_code, bool sync=true, int version=-1) const
Definition: zkwrapper.cc:478
bool recursive_create(const std::string &path, const std::vector< std::uint8_t > &data, int &error_code, bool sync=true) const
Definition: zkwrapper.cc:354
bool flush(const std::string &full_path, bool synchronous=false) const
Definition: zkwrapper.cc:780
bool create_sequential(const std::string &path, const std::vector< std::uint8_t > &data, std::string &new_path, bool ephemeral, int &error_code, bool sync=true) const
Definition: zkwrapper.cc:306
static std::string translate_error(int error_code)
Definition: zkwrapper.cc:71
friend void watcher(zhandle_t *zzh, int type, int state, const char *path, void *watcherCtx)
Definition: zkwrapper.cc:32
bool wget(const std::string &path, std::vector< std::uint8_t > &data, watcher_fn watch, void *watcherCtx, int &error_code, bool resize) const
Definition: zkwrapper.cc:384
std::shared_ptr< ZooOp > build_set_op(const std::string &path, const std::vector< std::uint8_t > &data, int version=-1) const
Definition: zkwrapper.cc:731
bool wget_children(const std::string &path, std::vector< std::string > &children, watcher_fn watch, void *watcherCtx, int &error_code) const
Definition: zkwrapper.cc:677
Definition: zkwrapper.h:62
std::string prepend_zk_root(const std::string &path) const
Definition: zkwrapper.cc:240
bool create(const std::string &path, const std::vector< std::uint8_t > &data, int &error_code, bool ephemeral, bool sync=true) const
Definition: zkwrapper.cc:271
bool execute_multi(const std::vector< std::shared_ptr< ZooOp >> operations, std::vector< zoo_op_result > &results, int &error_code, bool sync=true) const
Definition: zkwrapper.cc:745
std::shared_ptr< ZooOp > build_create_op(const std::string &path, const std::vector< std::uint8_t > &data, const int flags=0) const
Definition: zkwrapper.cc:707
bool get_children(const std::string &path, std::vector< std::string > &children, int &error_code) const
Definition: zkwrapper.cc:654
Definition: zkwrapper.h:34
bool exists(const std::string &path, bool &exist, int &error_code) const
Definition: zkwrapper.cc:508
bool get_info(const std::string &path, struct Stat &stat, int &error_code) const
Definition: zkwrapper.cc:584
ZKWrapper(const std::string &host, int &error_code, const std::string &root)
Definition: zkwrapper.cc:141
bool delete_node(const std::string &path, int &error_code, bool sync=true) const
Definition: zkwrapper.cc:562
bool wexists(const std::string &path, bool &exist, watcher_fn watch, void *watcherCtx, int &error_code) const
Definition: zkwrapper.cc:532
bool recursive_delete(const std::string &path, int &error_code) const
Definition: zkwrapper.cc:612