stateLock.writeLock().lock();
try {
if (!isChannelReady(channel)) {
LOG.debug("Connecting to " + remoteAddr);
ChannelFuture channelFuture = bootstrap.connect(remoteAddr);
channelFuture.awaitUninterruptibly(connectTimeoutMillis);
if (!channelFuture.isSuccess()) {
throw new IOException("Error connecting to " + remoteAddr,
channelFuture.getCause());
}
channel = channelFuture.getChannel();