Zookeeper Library for C + + encapsulation

Source: Internet
Author: User

Cppzk
---- Zookeeper Library for C + + encapsulation
Features:
1. C + + package, easy to use interface;
2. Fewer files, a header file and a source file, whether it is compiled into a library or direct source file compilation is very convenient;
3. Support the node's create, set, get, support watch;
4. Only Linux is supported for the time being.

Compile
The boost header file is required because boost::function is used as the callback function.

Under Linux:
CD src
Make-f makefile.mk
Generate LIBCPPZK.A


How to use

    #include "ZooKeeper.h"//contains header file        ZooKeeper ZK;//define Object    zk.init ("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183" );//Initialize, parameter is Zookeeper server address list, format: Ip:port,ip:port,...    Zk.exists (path);//Determine if the node exists    zk.createnode (path, data, recursive);//Recursive creation of nodes (Recursivce=false without recursive creation, Returns an error directly when the parent node does not exist)    Zk.createephemeralnode (path, data, recursive);//recursive creation of ephemeral nodes    Zk.createsequencenode ( Path, data, rpath, recursive); Recursive creation of the sequence node, rpath for the actual path returned    //watch    zk.watchdata (path, datacallback);//Watch node data, when the data changes, trigger callback function    Zk.watchchildren (path, childrencallback); Watch child node, when the child node is added or deleted, trigger callback function//    log    zk.setlogstream (stderr);//Set Log stream    Zk.setdebugloglevel (true); Turn on debug logging

The definition of Watch's callback:

    Two kinds of callback, data callback and child node callback    //Datawatchcallback return path and value of the path    //Childrenwatchcallback return path and sub-section name    under this path typedef boost::function<void (const std::string &path, const std::string &value) > datawatchcallback;    typedef boost::function<void (const std::string &path, const std::vector<std::string> &value) > Childrenwatchcallback;


For clarity, the above code omits the definition of error handling and some variables, and the complete code can be found in src/test.cc

:https://github.com/fdxuwei/cppzk

Zookeeper Library for C + + encapsulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.