zk系列-3.watch事件的分类/模式和服务端返回的代码

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);
   }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值