GithubHelp home page GithubHelp logo

zk_cpp's Introduction


zookeeper 官方只提供了 c client api, 没有c++的api,为了使用更加的方便,接口更加好用,估简单对c client进行了下封装,使c++用户用起来更方便

1. 一些静态的函数

这些函数主要是全局作用范围的

    /**
     * @brief get the errocode string
     */
    static const char*  error_string(int32_t rc);

    /** 
     * @brief state to string
     */
    static const char*  state_to_string(int32_t state);

    /** 
     * @brief set zookeeper client internal log level
     */
    static void         set_log_lvl(zoo_log_lvl lvl);

    /** 
     * @brief set the log stream
     */
    static void         set_log_stream(FILE* file);

2. 然后就是对节点的一些常规访问操作接口

  • 创建节点
	zoo_rc      create_persistent_node(const char* path, const std::string& value, const std::vector<zoo_acl_t>& acl);
	zoo_rc      create_sequence_node(const char* path, const std::string& value, const std::vector<zoo_acl_t>& acl, std::string& returned_path_name);
	zoo_rc      create_ephemeral_node(const char* path, const std::string& value, const std::vector<zoo_acl_t>& acl);
	zoo_rc      create_sequance_ephemeral_node(const char* path, const std::string& value, const std::vector<zoo_acl_t>& acl, std::string& returned_path_name);
  • 设置节点的值
 	zoo_rc      set_node(const char* path, const std::string& value, int32_t version);
  • 获取节点的值
 	zoo_rc      get_node(const char* path, std::string& out_value, zoo_state_t* info, bool watch);
  • 获取节点的所有子节点
	zoo_rc      get_children(const char* path, std::vector<std::string>& children, bool watch);
  • 删除节点
	zoo_rc      delete_node(const char* path, int32_t version);
  • 节点是否存在
	zoo_rc      exists_node(const char* path, zoo_state_t* info, bool watch);
  • 设置节点的acl
	zoo_rc      set_acl(const char* path, const std::vector<zoo_acl_t>& acl, int32_t version);
  • 获取节点的acl
	zoo_rc      get_acl(const char* path, std::vector<zoo_acl_t>& acl);
  • 添加权限认证
	zoo_rc      add_auth(const std::string& user_name, const std::string& user_passwd);

3. 设置一些事件回调

  • 设置节点的值变化的通知回调函数
	zoo_rc      watch_data_change(const char* path, const data_change_event_handler_t& handler, std::string* value);
  • 设置节点的子节点变化(增/减)的通知回调函数
	zoo_rc      watch_children_event(const char* path, const child_event_handler_t& handler, std::vector<std::string>* out_children );

4. 具体的使用见zk_cpp_test.cpp

zk_cpp's People

Contributors

yandaren avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.