Zookeeper[3] Zookeeper Summary of development considerations

Source: Internet
Author: User

This is based on the official Interface documentation (Http://zookeeper.apache.org/doc/r3.4.1/api/org/apache/zookeeper/ZooKeeper.html#register ( Org.apache.zookeeper.Watcher) and source code annotations are refined to guide the development of zookeeper.

1. Creating Zookeeper node:Create (String path, byte[] data, list<acl> ACL, Createmode createmode)

1) If the created node already exists, an exception is thrown: keeperexception.nodeexists, you need to determine whether the node already exists before creating the operation;

2) If the parent node does not exist, an exception is thrown: Keeperexception.nonode, so, when the node path is multi-layered, the node needs to be created by layer;

3) If the parent node of the path is created as a temporary node, an exception is thrown: Keeperexception.nochildrenforephemerals, remember that the child node cannot have child nodes;

4) If the data size exceeds 1M, an exception is thrown: Keeperexecption.

2. Close connection: public void close()

Once the client is closed, the reply to the use will be invalidated. At the same time, the temporary node associated with the reply on the zookeeper server will be deleted.

3. Delete the given path node:Delete(String path, int version)

1) If version is-1, any version of the node is matched;

2) If the node does not exist, throw an exception: Keeperexception.nonode, the need for Xi ' an to determine the existence of the path corresponding node before the delete operation;

3) If the value of version and the node version number do not match, an exception is thrown: keeperexception.badversion;

4) If the node has a child node, an exception is thrown: Keeperexception.notempty.

4, set the data to point node:setData(String path, byte[] data, int version)

1) If version is-1, any version of the node is matched;

2) If the given path node does not exist, throw an exception: Keeperexception.nonode, so before performing the set operation, you need to first determine whether the node exists;

3) If the given version and node version do not match, an exception is thrown: keeperexception.badversion;

4) If the data size exceeds 1M, an exception is thrown: Keeperexecption.

5. Determine if the specified path node exists,exists(String path, Watcher watcher)

1) returns NULL if the node does not exist;

2) If the Watcher is non-null and the operation executes successfully, the node of the given path is observed;

3) This observation is triggered by the increment/delete successful operation of the given path node and the successful setting of the node's data.

6. Get data for a given path node: byte[] getData(String path, Watcher Watcher, stat stat)

1) If the Watcher is non-null and the operation executes successfully, the node of the given path is observed;

2) A successful deletion of a given path node and the successful setting of the node's data will trigger the observation.

3) If the given path node does not exist, an exception is thrown: Keeperexception.nonode;

7. Get the child list for the given path node:list<string> getChildren (Final String path, watcher watcher)

1) If the Watcher is non-null and the operation executes successfully, the node of the given path is observed;

2) The successful deletion of the path node, and the successful creation or deletion of the node's child node, will start the observation;

3) The returned child node will not be sorted, neither guaranteed to be a dictionary or a natural order.

8. Get the child list and state structure of the given path node:list<string> getChildren (String path, Boolean watch, stat stat)

9. Register default observation: void Register(Watcher Watcher)

10, the use of the Sync () method:

If client a modifies the value of a node/A to 1 from 0 and then notifies client B to read/A, the value that client B reads to may still be 0, depending on which server it is connected to . If client A and B read to the same value is important, then client B should call the Sync () method before executing the read .

Zookeeper[3] Zookeeper Summary of development considerations

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.