private final List<RedisClient> sentinels = new ArrayList<RedisClient>();
public SentinelConnectionManager(final SentinelServersConfig cfg, Config config) {
init(config);
final MasterSlaveServersConfig c = new MasterSlaveServersConfig();
c.setLoadBalancer(cfg.getLoadBalancer());
c.setPassword(cfg.getPassword());
c.setDatabase(cfg.getDatabase());
c.setMasterConnectionPoolSize(cfg.getMasterConnectionPoolSize());
c.setSlaveConnectionPoolSize(cfg.getSlaveConnectionPoolSize());
c.setSlaveSubscriptionConnectionPoolSize(cfg.getSlaveSubscriptionConnectionPoolSize());
c.setSubscriptionsPerConnection(cfg.getSubscriptionsPerConnection());
final Set<String> addedSlaves = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
for (URI addr : cfg.getSentinelAddresses()) {
RedisClient client = new RedisClient(group, addr.getHost(), addr.getPort(), cfg.getTimeout());
RedisAsyncConnection<String, String> connection = client.connectAsync();
// TODO async
List<String> master = connection.getMasterAddrByKey(cfg.getMasterName()).awaitUninterruptibly().getNow();
String masterHost = master.get(0) + ":" + master.get(1);
c.setMasterAddress(masterHost);
log.info("master: {}", masterHost);
// c.addSlaveAddress(masterHost);
// TODO async
List<Map<String, String>> slaves = connection.slaves(cfg.getMasterName()).awaitUninterruptibly().getNow();
for (Map<String, String> map : slaves) {
String ip = map.get("ip");
String port = map.get("port");
log.info("slave: {}:{}", ip, port);
c.addSlaveAddress(ip + ":" + port);
String host = ip + ":" + port;
addedSlaves.add(host);
}
client.shutdown();