# # Zookeeper
> Zookeeper is currently used to do data synchronization before each service synchronizes key information
I. Client-side operation
1. Create
Create [-S] [-e] path data ACL
-S is the sequential node-e as a temporary node (the temporary node disappears after the session disappears)
ACL is permission control, permissions control is troublesome, and only exists at this node and this level, its child nodes are not controlled
2. Read
Ls:
LS Path
List all child nodes under this node
Get
Get path
Get the contents and properties of this node
3. Update
Set path data [version]
Version is optional and is based on which edition updates are selected
4. Delete
Delete path [version]
5. Permissions
On the No. 215 page of Zookeeper's book, we have a detailed description.
The digest encryption method is used here, using the method provided by the zookeeper to encrypt
II. Java Client Operations
Code Address: Zkservice.java
1. Initializing the Client
"' Java
Private Curatorframework client = Curatorframeworkfactory.builder ()
. connectstring (IP of zookeeper)
. Retrypolicy (New Exponentialbackoffretry (1000, 6))
. SESSIONTIMEOUTMS (5000)
. namespace (which address is the base)
. Authorization (encryption method, password)
. build ();
```
2. Register for monitoring
"' Java
private void Watch (String path) {
Executorservice TP = Executors.newfixedthreadpool (2);
System.out.println (Thread.CurrentThread (). GetName ());
Pathchildrencache cache = New Pathchildrencache (here the initialized client is passed in, here the listener's address, true, FALSE, TP);
try {
Cache.start (PathChildrenCache.StartMode.NORMAL);
} catch (Exception e) {
E.printstacktrace ();
}
Cache.getlistenable (). AddListener (New Pathchildrencachelistener () {
public void Childevent (Curatorframework client,
Pathchildrencacheevent event) throws Exception {
Switch (Event.gettype ()) {
Case child_added://Here are three switch corresponding to three operations, which write the implementation of the business logic
Listenservice.inituser (New String (Event.getdata ())); Event.getdata () is the fetch data
Break
Case child_updated:
Break
Case child_removed:
Break
Default
Break
}
}
});
}
```
3. Create
```
String Path = "Custom";
try {
Client.getclient (). Create ()
. Withmode (createmode.persistent_sequential)//This is a sequential persistent node (automatically adds a number to the node in order), sequential is a simple persistent node
. Forpath (address here, "transmit data here");
} catch (Exception e) {
E.printstacktrace ();
}
```
Zookeeper client base operations and Java calls