Search in sources :

Example 1 with DefaultLeaderElector

use of com.ctrip.xpipe.cluster.DefaultLeaderElector 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();
}
Also used : ElectContext(com.ctrip.xpipe.cluster.ElectContext) DefaultLeaderElector(com.ctrip.xpipe.cluster.DefaultLeaderElector) LeaderElector(com.ctrip.xpipe.api.cluster.LeaderElector) DefaultLeaderElector(com.ctrip.xpipe.cluster.DefaultLeaderElector) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Aggregations

LeaderElector (com.ctrip.xpipe.api.cluster.LeaderElector)1 DefaultLeaderElector (com.ctrip.xpipe.cluster.DefaultLeaderElector)1 ElectContext (com.ctrip.xpipe.cluster.ElectContext)1 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)1