final CommandHandler<K, V> commandHandler = new CommandHandler<K, V>(queue);
final RedisSentinelAsyncConnectionImpl<K, V> connection = new RedisSentinelAsyncConnectionImpl<K, V>(commandHandler,
codec, timeout, unit);
logger.debug("Trying to get a Sentinel connection for one of: " + redisURI.getSentinels());
final Bootstrap sentinelBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(group);
final ConnectionWatchdog watchdog = new ConnectionWatchdog(sentinelBootstrap, timer);
watchdog.setReconnect(true);
sentinelBootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(watchdog, new ChannelGroupListener(channels), watchdog, commandHandler,
new ConnectionEventTrigger(connectionEvents, connection));
}
});
if (redisURI.getSentinels().isEmpty() && LettuceStrings.isNotEmpty(redisURI.getHost())) {
sentinelBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
(int) redisURI.getUnit().toMillis(redisURI.getTimeout()));
ChannelFuture connect = sentinelBootstrap.connect(redisURI.getResolvedAddress());
logger.debug("Connecting to Sentinel, address: " + redisURI.getResolvedAddress());
try {
connect.sync();
} catch (InterruptedException e) {
throw new RedisException(e.getMessage(), e);
}
} else {
boolean connected = false;
Exception causingException = null;
for (RedisURI uri : redisURI.getSentinels()) {
sentinelBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) uri.getUnit().toMillis(uri.getTimeout()));
ChannelFuture connect = sentinelBootstrap.connect(uri.getResolvedAddress());
logger.debug("Connecting to Sentinel, address: " + uri.getResolvedAddress());
try {
connect.sync();
connected = true;
} catch (Exception e) {