init(config);
Map<String, ClusterPartition> partitions = new HashMap<String, ClusterPartition>();
for (URI addr : cfg.getNodeAddresses()) {
RedisClient client = new RedisClient(group, addr.getHost(), addr.getPort(), cfg.getTimeout());
RedisAsyncConnection<String, String> connection = client.connectAsync();
String nodesValue = connection.clusterNodes().awaitUninterruptibly().getNow();
System.out.println(nodesValue);
List<ClusterNodeInfo> nodes = parse(nodesValue);
for (ClusterNodeInfo clusterNodeInfo : nodes) {
String id = clusterNodeInfo.getNodeId();
if (clusterNodeInfo.getFlags().contains(Flag.SLAVE)) {
id = clusterNodeInfo.getSlaveOf();
}
ClusterPartition partition = partitions.get(id);
if (partition == null) {
partition = new ClusterPartition();
partitions.put(id, partition);
}
if (clusterNodeInfo.getFlags().contains(Flag.FAIL)) {
partition.setMasterFail(true);
}
if (clusterNodeInfo.getFlags().contains(Flag.SLAVE)) {
partition.addSlaveAddress(clusterNodeInfo.getAddress());
} else {
partition.setEndSlot(clusterNodeInfo.getEndSlot());
partition.setMasterAddress(clusterNodeInfo.getAddress());
}
}
for (ClusterPartition partition : partitions.values()) {
if (partition.isMasterFail()) {
continue;
}
MasterSlaveServersConfig c = create(cfg);
log.info("master: {}", partition.getMasterAddress());
c.setMasterAddress(partition.getMasterAddress());
for (String slaveAddress : partition.getSlaveAddresses()) {
log.info("slave: {}", slaveAddress);
c.addSlaveAddress(slaveAddress);
}
MasterSlaveEntry entry = new MasterSlaveEntry(codec, group, c);
entries.put(partition.getEndSlot(), entry);
}
client.shutdown();
break;
}
this.config = create(cfg);
}