Use of zookeeper---java program

Source: Internet
Author: User
Tags call back zookeeper

First, guide the storage
    1. The following inventory is placed in the directory Lib:
audience-annotations-0.5.0.jarjline-0.9.94.jarlog4j-1.2.17.jarnetty-3.10.6.final.jarslf4j-api-1.7.25.jarslf4j-log4j12-1.7 .25.jar
    1. The following inventory is placed in the root directory of the zookeeper installation:
Zookeeper-3.4.12.jar second, the operation of the Zookeeper object
    1. Creation of Zookeeper objects
String connectstring = "hadoop1:2181,hadoop2:2181,hadoop3:2181"; int sessiontimeout =newnew  watcher () {@Override Public void process (Watchedevent event) {...}});
Where: ConnectString is the connection zookeeper information Sessiontimeout is the session timeout time, that is, when a zookeeper more than the time there is no heartbeat, it is considered that the node failure. The Watcher is a monitor that, once triggered, will call back to the process method, and the event triggered will exist in the events object.
    1. Common methods for Zookeeper objects
Method name return value Role Each parameter Note
String Create (Final String path, byte data[], list<acl> acl,createmode createmode) The return value is a string of path Create a Node
  1. Path is the creation of a node path
  2. Data is the value in the node
  3. ACLs are permissions that can be obtained through an enumeration of IDs classes
  4. Createmode is a created type with four types, namely: Permanent, permanent serialization, short, ephemeral serialization.
Stat setData (Final String path, byte data[], int version) A node state object that contains various information about the node, including the version of the node change, the date the node was created, and so on. Set the data for a node
  1. Path is the node path that modifies the data
  2. Data is the value after the modification
  3. Version is the revision of the node, 1 means all nodes
List<string> GetChildren (String path, Boolean watch) Node subnodes collection, only node name, not full path Get a list of child nodes
  1. Path is the parent node path.
  2. Watch is whether to monitor the change of child nodes
Byte[] GetData (String path, Boolean watch, stat stat) The value of the node Gets the value of the node
  1. Path is the node
  2. Watch is whether to monitor the data changes of the node
  3. Stat is the node that is explicitly in which state, and can be set to null.
void Delete (final String path, int version) Delete a node
  1. Path is the node
  2. Version is a node, 1 means that all versions of the node are deleted

Use of zookeeper---java program

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.