本文整理了Java中me.hao0.antares.common.zk.ZkClient.acquireLeader()
方法的一些代码示例,展示了ZkClient.acquireLeader()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZkClient.acquireLeader()
方法的具体详情如下:
包路径:me.hao0.antares.common.zk.ZkClient
类名称: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();
}
内容来源于网络,如有侵权,请联系作者删除!