1.事件的種類
2.事件的模式
在調用getData
等方法添加的watcher都是一次性的,調用後就被移除掉了。通過addWatcher可以添加持續性事件。分爲以下兩種:
PERSISTENT(ZooDefs.AddWatchModes.persistent)
PERSISTENT_RECURSIVE(ZooDefs.AddWatchModes.persistentRecursive)
PERSISTENT:在給定的路徑上設置一個觀察者,該觀察者在觸發時不會被刪除(即,它一直處於活動狀態直到被刪除)。數據和子事件均觸發此監視程序。要刪除監視程序,請對 WatcherType.Any
使用 removeWatches()
。該監視程序的行爲就像您在給定路徑的ZNode上放置了一個exist()
監視和一個getData()
監視一樣。
PERSISTENT_RECURSIVE:在給定的路徑上設置觀察者:a)觸發時不會被刪除(即,直到被刪除,它一直處於活動狀態); b)不僅適用於註冊路徑,而且適用於所有子路徑。數據和子事件均觸發此監視程序。要刪除監視程序,請將 removeWatches()
與WatcherType.Any
一起使用,監視程序的行爲就像您放置了一個exist()
監視程序和一個getData( )
在給定路徑上觀察ZNode,並在給定路徑的子節點上監視所有ZNode,包括稍後添加的子節點。 >注意:當存在活動的遞歸監視時,性能會有所降低,因爲必須檢查ZNode路徑的所有段以進行監視觸發。
3.服務端返回的代碼
public enum Code implements CodeDeprecated {
/** Everything is OK */
OK(Ok),
/** System and server-side errors.
* This is never thrown by the server, it shouldn't be used other than
* to indicate a range. Specifically error codes greater than this
* value, but lesser than {@link #APIERROR}, are system errors.
*/
SYSTEMERROR(SystemError),
/** A runtime inconsistency was found */
RUNTIMEINCONSISTENCY(RuntimeInconsistency),
/** A data inconsistency was found */
DATAINCONSISTENCY(DataInconsistency),
/** Connection to the server has been lost */
CONNECTIONLOSS(ConnectionLoss),
/** Error while marshalling or unmarshalling data */
MARSHALLINGERROR(MarshallingError),
/** Operation is unimplemented */
UNIMPLEMENTED(Unimplemented),
/** Operation timeout */
OPERATIONTIMEOUT(OperationTimeout),
/** Invalid arguments */
BADARGUMENTS(BadArguments),
/** No quorum of new config is connected and up-to-date with the leader of last commmitted config - try
* invoking reconfiguration after new servers are connected and synced */
NEWCONFIGNOQUORUM(NewConfigNoQuorum),
/** Another reconfiguration is in progress -- concurrent reconfigs not supported (yet) */
RECONFIGINPROGRESS(ReconfigInProgress),
/** Unknown session (internal server use only) */
UNKNOWNSESSION(UnknownSession),
/** API errors.
* This is never thrown by the server, it shouldn't be used other than
* to indicate a range. Specifically error codes greater than this
* value are API errors (while values less than this indicate a
* {@link #SYSTEMERROR}).
*/
APIERROR(APIError),
/** Node does not exist */
NONODE(NoNode),
/** Not authenticated */
NOAUTH(NoAuth),
/** Version conflict
In case of reconfiguration: reconfig requested from config version X but last seen config has a different version Y */
BADVERSION(BadVersion),
/** Ephemeral nodes may not have children */
NOCHILDRENFOREPHEMERALS(NoChildrenForEphemerals),
/** The node already exists */
NODEEXISTS(NodeExists),
/** The node has children */
NOTEMPTY(NotEmpty),
/** The session has been expired by the server */
SESSIONEXPIRED(SessionExpired),
/** Invalid callback specified */
INVALIDCALLBACK(InvalidCallback),
/** Invalid ACL specified */
INVALIDACL(InvalidACL),
/** Client authentication failed */
AUTHFAILED(AuthFailed),
/** Session moved to another server, so operation is ignored */
SESSIONMOVED(-118),
/** State-changing request is passed to read-only server */
NOTREADONLY(-119),
/** Attempt to create ephemeral node on a local session */
EPHEMERALONLOCALSESSION(EphemeralOnLocalSession),
/** Attempts to remove a non-existing watcher */
NOWATCHER(-121),
/** Request not completed within max allowed time.*/
REQUESTTIMEOUT(-122),
/** Attempts to perform a reconfiguration operation when reconfiguration feature is disabled. */
RECONFIGDISABLED(-123),
/** The session has been closed by server because server requires client to do SASL authentication,
* but client is not configured with SASL authentication or configuted with SASL but failed
* (i.e. wrong credential used.). */
SESSIONCLOSEDREQUIRESASLAUTH(-124);
}