use of com.ctrip.xpipe.api.cluster.LeaderElector in project x-pipe by ctripcorp.
the class DefaultKeeperElectorManagerTest method addKeeperZkNode.
private void addKeeperZkNode(String clusterId, String shardId, ZkClient zkClient, int idLen) throws Exception {
String leaderElectionZKPath = MetaZkConfig.getKeeperLeaderLatchPath(clusterId, shardId);
String leaderElectionID;
if (idLen == 0) {
leaderElectionID = MetaZkConfig.getKeeperLeaderElectionId(new KeeperMeta());
} else {
leaderElectionID = MetaZkConfig.getKeeperLeaderElectionId(new KeeperMeta().setId(randomString(idLen)));
}
ElectContext ctx = new ElectContext(leaderElectionZKPath, leaderElectionID);
LeaderElector leaderElector = new DefaultLeaderElector(ctx, zkClient.get());
leaderElector.elect();
}
Aggregations