in bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/grpc/GrpcClient.java [88:122]
private static ManagedChannel createChannel(String host, Integer port) {
String ipv4;
try {
InetAddress address = InetAddress.getByName(host);
ipv4 = address.getHostAddress();
} catch (Exception e) {
log.error("Unable to resolve host: {}", host);
throw new ApiException(ApiExceptionEnum.HOST_UNABLE_TO_RESOLVE, host);
}
ManagedChannel channel = ManagedChannelBuilder.forAddress(ipv4, port)
.usePlaintext()
.keepAliveTime(60, TimeUnit.SECONDS)
.keepAliveWithoutCalls(true)
.build();
ConnectivityState state = channel.getState(true);
while (state == ConnectivityState.IDLE || state == ConnectivityState.CONNECTING) {
try {
Thread.sleep(1000);
state = channel.getState(true);
} catch (Exception e) {
log.warn("Error ignored when creating channel", e);
}
}
if (state != ConnectivityState.READY) {
channel.shutdown();
log.error("Unable to connect to host: {}", host);
throw new ApiException(ApiExceptionEnum.HOST_UNABLE_TO_CONNECT, host);
} else {
CHANNELS.put(host, channel);
return channel;
}
}