Java API operations for zookeeper

Source: Internet
Author: User
Tags zookeeper

Java API operations for zookeeperTo create a session:Zookeeper (String connectstring,int sessiontimeout,watcher Watcher)Zookeeper (String connectstring,int sessiontimeout,watcher watcher,boolean canbereadonly)Zookeeper (String connectstring,int sessiontimeout,watcher watcher,long sessionid,byte[] sessionpasswd)Zookeeper (String connectstring,int sessiontimeout,watcher watcher,long sessionid,byte[] Sessionpasswd,boolean Canbereadonly)parameter Description:connectstring-Host:port[,host:port][basepath] Specifies a list of servers, separated by commas between multiple host:port. Optionally, you can specify a base path, and if a base path is specified, all subsequent operations are based on this and the path. Sessiontimeout-session time-out. in milliseconds. The connection between the client and the server is maintained through the heartbeat packet and the session timeout is considered invalid if the heartbeat packet exceeds this specified time. Watcher--Specifies the default observer. If NULL indicates that no observer is required. canbereadonly--read-only service is supported. Whether the read operation continues to be supported when a server loses more than half of the connections and cannot write again. SlightlySessionId, Sessionpassword-session number session password for session recovery. * * Note that the process of creating a session is asynchronous, and the construction method returns after the connection is initialized, and does not mean that a session is actually established and the session is in the "Connecting" state. * * When a session is actually created, the server sends an event notification to the client, and only after the client obtains the notification does the session actually build. Code://todoTo Create a node:string Create (Final String path,byte data[],list<acl> acl,createmode createmode);//synchronous mode creationvoid Create (Final String path,byte data[],list<acl> acl,createmode createmode,stringcallback cb,object ctx) ;//Asynchronous Creationparameter Description:path of the data node to be created by pathdata [] When the node is created, the initial contentACL node ACL security PolicyCreatemode Creating a patternPersistent Durablepersistent_sequential Persistence sequenceEphemeral temporaryephemeral_sequential Temporary OrderCB Callback Interfacectx Transitive object, used in callback methods, usually a context object* * Note: Recursive creation is not supported, i.e. child nodes cannot be created without a parent node* * Attempts to create an existing node will fail and throw an exception* * When no permission control is required, simply pass in the Ids.open_acl_unsafeCode://todoTo Delete a node:Public void Delete (final String path,int version)Public void Delete (final String path,int version,voidcallback cb,object ctx)* * Note: You cannot delete a node that has child nodes, that is, if you want to delete a node, you must first delete all of its child nodesRead data:GetChildren//Sync modelist<string> GetChildren (final String Path,watcher watcher)list<string> GetChildren (String path,boolean Watch)list<string> GetChildren (final String path,watcher watcher,stat Stat)list<string> GetChildren (String path,boolean watch,stat Stat)//Async modevoid getchildred (final String path,watcher watcher,childrencallback cb,object ctx)void getchildred (String path,boolean watch,childredncallback cb,object ctx)void getchildred (final String path,watcher watcher,children2callback cb,object ctx)void getchildred (String path,boolean watch,children2callback cb,object ctx)parameter Description:path of the data node to be created by pathWatcher Observer, once the child node list is changed after the book node is acquired, the server sends a message to the client, triggering a callback in the watcher. Note that just notice, if you need a new sub-node list, you need to get it again. Allow NULL to be passed in. Watch indicates if you need to register a watcher. True to notify default to default Watcher, or false to not useCB back-off functionCTX Context ObjectStat Specifies the status information for the data node. The usage is to pass in an old stat variable in the interface, which is replaced by a new stat object from the server response during the execution of the method. GetData//Sync modeByte [] getData (Final String Path,watcher Watcher, stat stat)Byte [] getData (String Path,boolean Watch, stat stat)//Async modevoid GetData (final String Path,watcher Watcher, Datacallback cb,object ctx)void GetData (String path,boolean Watch, Datacallback cb,object ctx)* can be monitored by registering watcher, once the node data is updated will notify the clientUpdate Data//Sync modeStat setData (final String path,byte data[],int version)//version can pass in-1, indicating that the update operation is based on the latest version//Async modevoid SetData (final String path,byte data[],int version,statcallback cb,object ctx)Check if the node exists//Sync modePublic Stat exists (final String Path,watcher watcher)Public Stat exists (String Path,boolean watch)//Async modePublic Stat exists (final String path,watcher watcher,statcallback cb,object ctx)Public Stat exists (String path,boolean watch,statcallback cb,object ctx)* can be monitored by registering watcher, once the node is created, deleted, the data is updated will notify the clientZookeeper Permissions Control:Addauthinfo (String schema,byte [] auth)parameter description;schema permission mode, can be World Auth Digest IP Super, we use digestbyte[] Auth rights control identification, composed of "foo:123". GetByte (), subsequent operations only the same Auth value can be* * Note the delete operation, if the node is increased when the permission is specified, for the delete operation, it is assumed that the permissions are added to the child node, delete the current node does not require permissions, delete child nodes need permission.

Java API operations for zookeeper

Related Article

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.