ip2client.put(hostport, client); // This is guaranteed to return null.
}
client2regions.put(client, new ArrayList<RegionInfo>());
num_connections_created.increment();
// Configure and connect the channel without locking ip2client.
final SocketChannelConfig config = chan.getConfig();
config.setConnectTimeoutMillis(5000);
config.setTcpNoDelay(true);
// Unfortunately there is no way to override the keep-alive timeout in
// Java since the JRE doesn't expose any way to call setsockopt() with
// TCP_KEEPIDLE. And of course the default timeout is >2h. Sigh.
config.setKeepAlive(true);
chan.connect(new InetSocketAddress(host, port)); // Won't block.
return client;
}