Watcher settings are the most common in development. You need to understand some basic features of watcher. Different watcher information is received for different operations on nodes of exists, getdata, and getchild. The change of the parent node and the sun node will not trigger watcher, but the change of the watcher node and the child node will trigger watcher. For details, refer to the table below.
Operation |
Method |
Trigger watcher |
Watcher state |
Watcher type |
Watcher path |
Create current node |
Getdata |
× |
× |
× |
× |
Getchildren |
√ |
3 |
4 |
√ |
Exists |
× |
× |
× |
× |
Set current node |
Getdata |
√ |
3 |
3 |
√ |
Getchildren |
× |
× |
× |
× |
Exists |
√ |
3 |
3 |
√ |
Delete current node |
Getdata |
√ |
3 |
2 |
√ |
Getchildren |
√ |
3 |
2 |
√ |
Exists |
√ |
3 |
2 |
√ |
Create subnode |
Getdata |
× |
× |
× |
× |
Getchildren |
√ |
3 |
4 |
√ |
Exists |
× |
× |
× |
× |
Set subnode |
Getdata |
× |
× |
× |
× |
Getchildren |
× |
× |
× |
× |
Exists |
× |
× |
× |
× |
Delete subnode |
Getdata |
× |
× |
× |
× |
Getchildren |
√ |
3 |
4 |
√ |
Exists |
× |
× |
× |
× |
Restore connection |
Getdata |
√ |
1 |
-1 |
× |
Getchildren |
√ |
1 |
-1 |
× |
Exists |
√ |
1 |
-1 |
× |
Session restoration has not timed out. |
Getdata |
√ |
-112 |
-1 |
× |
Getchildren |
√ |
-112 |
-1 |
× |
Exists |
√ |
-112 |
-1 |
× |
Session restoration timeout |
Getdata |
√ |
3 |
-1 |
× |
Getchildren |
√ |
3 |
-1 |
× |
Exists |
√ |
3 |
-1 |
× |
Note: State = 2 indicates the deletion event; State = 3 indicates the node data change; State = 4 indicates the subnode event; State =-1 indicates the session event. Type =-112 indicates that the session is invalid; type = 1 indicates that the session is being established; tpye = 3 indicates that the session is successfully established. * Indicates no, and √ indicates yes.
Zookeeper watch reference table