ZooKeeper Main Operation Demo sample

Source: Internet
Author: User

 //Create a connection to the serverZooKeeper ZK =NewZooKeeper ("localhost:" +Client_port, Clientbase.connection_timeout,NewWatcher () {//monitor all events that are triggered             Public voidprocess (Watchedevent event) {System.out.println ("The + event.gettype () +" event has been triggered! ");  }         }); //Create a folder nodeZk.create ("/testrootpath", "Testrootdata". GetBytes (), Ids.open_acl_unsafe, createmode.persistent); //Create a sub-folder nodeZk.create ("/testrootpath/testchildpathone", "Testchilddataone". GetBytes (), ids.open_acl_unsafe,createmode.persistent); System.out.println (NewString (Zk.getdata ("/testrootpath",false,NULL))); //Remove subfolders Node ListSystem.out.println (Zk.getchildren ("/testrootpath",true)); //Changing subfolder node dataZk.setdata ("/testrootpath/testchildpathone", "Modifychilddataone". GetBytes (),-1); System.out.println ("Folder node Status: [" +zk.exists ("/testrootpath",true)+"]"); //Create another sub-folder nodeZk.create ("/testrootpath/testchildpathtwo", "Testchilddatatwo". GetBytes (), ids.open_acl_unsafe,createmode.persistent); System.out.println (NewString (Zk.getdata ("/testrootpath/testchildpathtwo",true,NULL))); //To Delete a sub-folder nodeZk.delete ("/testrootpath/testchildpathtwo", 1); Zk.delete ("/testrootpath/testchildpathone",-1); //Delete parent folder nodeZk.delete ("/testrootpath", 1); //Close ConnectionZk.close ();

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

ZooKeeper Main Operation Demo sample

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.