Watcher Setup is the most common development, need to understand some of the basic characteristics of watcher, for exists, GetData, getchild for the different operations of the node will receive different watcher information
state=-112 Session Timeout Status
State=-113 Authentication failed status
State= 1 Connection Setup
State= 2 (temporarily unclear how to understand this state, zoo_associating_state)
STATE=3 Connection established status
state= 999 no Connection status
Type=1 Creating node Events
type=2 Deleting node events
Type=3 Changing node Events
Type=4 child Node List Change event
Type=-1 Sessions Session event
Type=-2 Monitoring removed events
Changes to the parent node and changes to the grandchild node do not trigger watcher, and changes to the watcher itself and child nodes trigger watcher, as specified in the following table.
Operation |
Method |
Trigger Watcher |
Watcher State |
Watcher Type |
Watcher Path |
Create current node |
GetData |
X |
X |
X |
X |
GetChildren |
√ |
3 |
4 |
√ |
Exists |
X |
X |
X |
X |
Set current node |
GetData |
√ |
3 |
3 |
√ |
GetChildren |
X |
X |
X |
X |
Exists |
√ |
3 |
3 |
√ |
Delete current node |
GetData |
√ |
3 |
2 |
√ |
GetChildren |
√ |
3 |
2 |
√ |
Exists |
√ |
3 |
2 |
√ |
Create child node |
GetData |
X |
X |
X |
X |
GetChildren |
√ |
3 |
4 |
√ |
Exists |
X |
X |
X |
X |
Set child node |
GetData |
X |
X |
X |
X |
GetChildren |
X |
X |
X |
X |
Exists |
X |
X |
X |
X |
Delete child node |
GetData |
X |
X |
X |
X |
GetChildren |
√ |
3 |
4 |
√ |
Exists |
X |
X |
X |
X |
Restore connection |
GetData |
√ |
1 |
-1 |
X |
GetChildren |
√ |
1 |
-1 |
X |
Exists |
√ |
1 |
-1 |
X |
Restore connection session not timed out |
GetData |
√ |
-112 |
-1 |
X |
GetChildren |
√ |
-112 |
-1 |
X |
Exists |
√ |
-112 |
-1 |
X |
Restore Connection Session Timeout |
GetData |
√ |
3 |
-1 |
X |
GetChildren |
√ |
3 |
-1 |
X |
Exists |
√ |
3 |
-1 |
X |
Note:x indicates no, √ indicates yes.
This article from the former CSDN blog, the full text address please click: 41726279?utm_source=copy
Zookeeper how to set up and get watcher correctly