Zookeeper.net Client (iii) "Znode node deletion and change check" __.net

Source: Internet
Author: User
Tags zookeeper
The most capable people are those who continue to transmit successful ideas, even in the most desperate circumstances. They not only inspire themselves, but also inspire others, not to achieve success, the oath to stop. --Anthony Robin
Class Program {static void Main (string[] args) {//Create a zookeeper instance, the first parameter is the destination server address and port, and the second parameter The number is the session timeout, and the third is the callback method using (Zookeeper ZK = new Zookeeper ("127.0.0.1:2181", New TimeSpan (0, 0, 0, 50) when the node changes. ), New Watcher ()) {var stat = ZK.
                Exists ("/root", true);   
                    if (stat = = null) {//Create a node root, the data is MyData, no ACL rights control, the node is permanent (that is, the client shutdown will not disappear) Zk. Create ("/root", "MyData Ling Feng". 
                GetBytes (), Ids.open_acl_unsafe, createmode.persistent); ///Create a childone znode under root, the data is Childone, ACL permissions are not controlled, nodes are permanent Console.WriteLine (DATETIME.N
                Ow+ ", (estimated) Start to create a millisecond position:" +datetime.now.millisecond); Console.WriteLine (ZK. Create ("/root/childone", "Childone".
                GetBytes (), Ids.open_acl_unsafe, createmode.persistent)); Gets the name of the child node under the/root node, and returns List<string> Console.WriteLine (ZK. GetchildrEn ("/root", true).
                Count ()); Gets the data under the/root/childone node and returns byte[] Console.WriteLine (ZK.

                GetData ("/root/childone", True, null));

                   Modify the data under the node/root/childone, the third parameter is version, if it is-1, it will disregard the modified version of the data, and directly change the stat structure of each znode in/*zookeeper by the following fields: Czxid: Zxid Mzxid of the transaction that created the node: Zxid CTime that was most recently modified by Znode: The number of milliseconds from the origin of the distance (epoch) Build time Mtime: Znode Last Modified time Version:znode data modified by the number of milliseconds from the distance Time origin (epoch) c Version:znode the number of child node modifications aversion:znode The number of ACL modifications Ephemeralowner: If Znode is a temporary node, the session I of the node owner is indicated
                   D; If it is not a temporary node, zero.
                   Datalength:znode data length.
                Numchildren:znode number of child nodes. */long time = ZK. SetData ("/root/childone", "childonemodify"). GetBytes (),-1).
                Ctime; Console.WriteLine (Encoding.UTF8.GetString, ZK. GetData ("/root/childone", true, null))); Console.WriteLine (Convertintdatetime (Time) + ", the actual number of milliseconds to create the position:" + convertintdatetime (time).
                millisecond); Delete/root/childone This node, the second parameter is version,-1 words are deleted directly, ignoring the version ZK.

            Delete ("/root/childone",-1);

        } console.readkey (); ///<summary>///converts a UNIX timestamp to datetime type Time///</summary>///<param Nam  E= "D" >double-type digital </param>///<returns>DateTime</returns> public static System.DateTime
            Convertintdatetime (double D) {System.DateTime time = System.DateTime.MinValue;
            System.DateTime starttime = TimeZone.CurrentTimeZone.ToLocalTime (New System.DateTime (1970, 1, 1));
            Time = Starttime.addmilliseconds (d);
        return time; }
    }
Run as shown:

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.