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

x33g5p2x  于2022-02-05 转载在 其他  
字(1.3k)|赞(0)|评价(0)|浏览(159)

本文整理了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();
}

相关文章