gpt4 book ai didi

me.hao0.antares.common.zk.ZkClient.acquireLeader()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 23:01:31 26 4
gpt4 key购买 nike

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

ZkClient.acquireLeader介绍

[英]Acquire the leadership
[中]获得领导权

代码示例

代码示例来源:origin: ihaolin/antares

/**
 * Acquire the leadership
 * @param leaderPath the leader node path
 * @param listener the leader listener
 * @return the leadership
 */
public Leader acquireLeader(String leaderPath, LeaderListener listener){
  return acquireLeader(null, leaderPath, listener);
}

代码示例来源:origin: ihaolin/antares

@Override
public void doStart(){
  leader = zk.client().acquireLeader(host.get(), ZkPaths.LEADER, new LeaderListener() {
    @Override
    public void isLeader() {
      Logs.info("The server {} become the leader.", host.get());
      // start the client failover
      clientFailover.start();
      // start the zk cleaner
      zkCleaner.start();
      // set the lead's host
      zk.client().update(ZkPaths.LEADER, host.get());
      // start the leader check task
      // avoid that the leader disconnect, because of network jitter
      scheduler = Executors.newScheduledThreadPool(1);
      scheduler.scheduleAtFixedRate(new LeaderCheckTask(), 1, 5, TimeUnit.SECONDS);
    }
  });
  // start the server failover with each server
  // avoid that the leader crashed and can't failover its jobs
  serverFailover.start();
}

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