gpt4 book ai didi

com.twitter.finagle.common.zookeeper.ZooKeeperClient.register()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 11:06:53 24 4
gpt4 key购买 nike

本文整理了Java中com.twitter.finagle.common.zookeeper.ZooKeeperClient.register()方法的一些代码示例,展示了ZooKeeperClient.register()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperClient.register()方法的具体详情如下:
包路径:com.twitter.finagle.common.zookeeper.ZooKeeperClient
类名称:ZooKeeperClient
方法名:register

ZooKeeperClient.register介绍

[英]Clients that need to register a top-level Watcher should do so using this method. The registered watcher will remain registered across re-connects and session expiration events.
[中]需要注册顶级观察者的客户端应该使用此方法。注册的观察者将在重新连接和会话过期事件中保持注册状态。

代码示例

代码示例来源:origin: com.twitter/finagle-serversets

/**
 * Clients that need to re-establish state after session expiration can register an
 * {@code onExpired} command to execute.
 *
 * @param onExpired the {@code Runnable} to register
 * @return the new {@link Watcher} which can later be passed to {@link #unregister} for
 *     removal.
 */
public Watcher registerExpirationHandler(final Runnable onExpired) {
 Watcher watcher = new Watcher() {
  @Override public void process(WatchedEvent event) {
   if (event.getType() == EventType.None && event.getState() == KeeperState.Expired) {
    onExpired.run();
   }
  }
 };
 register(watcher);
 return watcher;
}

代码示例来源:origin: com.twitter/finagle-serversets_2.11

/**
 * Clients that need to re-establish state after session expiration can register an
 * {@code onExpired} command to execute.
 *
 * @param onExpired the {@code Runnable} to register
 * @return the new {@link Watcher} which can later be passed to {@link #unregister} for
 *     removal.
 */
public Watcher registerExpirationHandler(final Runnable onExpired) {
 Watcher watcher = new Watcher() {
  @Override public void process(WatchedEvent event) {
   if (event.getType() == EventType.None && event.getState() == KeeperState.Expired) {
    onExpired.run();
   }
  }
 };
 register(watcher);
 return watcher;
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com