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: