Watcher 設置是開發中最多見的,需要弄清楚watcher的1些基本特點,對exists、getdata、getchild對節點的不同操作會收到不同的 watcher信息
對父節點的變更和孫節點的變更都不會觸發watcher,而對watcher本身節點和子節點的變更會觸發watcher,具體參照下表。
操作 | 方法 | 觸發watcher | watcher state | watcher type | watcher path |
Create當前節點 | getdata | × | × | × | × |
getchildren | √ | 3 | 4 | √ | |
exists | × | × | × | × | |
set當前節點 | getdata | √ | 3 | 3 | √ |
getchildren | × | × | × | × | |
exists | √ | 3 | 3 | √ | |
delete當前節點 | getdata | √ | 3 | 2 | √ |
getchildren | √ | 3 | 2 | √ | |
exists | √ | 3 | 2 | √ | |
create子節點 | getdata | × | × | × | × |
getchildren | √ | 3 | 4 | √ | |
exists | × | × | × | × | |
set子節點 | getdata | × | × | × | × |
getchildren | × | × | × | × | |
exists | × | × | × | × | |
delete子節點 | getdata | × | × | × | × |
getchildren | √ | 3 | 4 | √ | |
exists | × | × | × | × | |
恢復連接 | getdata | √ | 1 | ⑴ | × |
getchildren | √ | 1 | ⑴ | × | |
exists | √ | 1 | ⑴ | × | |
恢復連接session未超時 | getdata | √ | ⑴12 | ⑴ | × |
getchildren | √ | ⑴12 | ⑴ | × | |
exists | √ | ⑴12 | ⑴ | × | |
恢復連接session超時 | getdata | √ | 3 | ⑴ | × |
getchildren | √ | 3 | ⑴ | × | |
exists | √ | 3 | ⑴ | × |
注:×表示否,√表示是。
更多參見 http://tech.uc.cn/?p=1189,不過該文章中第5節對event和state的說明有誤,請仔細辨別。