in frontend/server/src/main/java/com/amazonaws/ml/mms/ModelServer.java [240:299]
public ChannelFuture initializeServer(
Connector connector,
EventLoopGroup serverGroup,
EventLoopGroup workerGroup,
ConnectorType type)
throws InterruptedException, IOException, GeneralSecurityException {
final String purpose = connector.getPurpose();
Class<? extends ServerChannel> channelClass = connector.getServerChannel();
logger.info("Initialize {} server with: {}.", purpose, channelClass.getSimpleName());
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024)
.channel(channelClass)
.childOption(ChannelOption.SO_LINGER, 0)
.childOption(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childOption(
ChannelOption.RCVBUF_ALLOCATOR,
new FixedRecvByteBufAllocator(MAX_RCVBUF_SIZE));
b.group(serverGroup, workerGroup);
SslContext sslCtx = null;
if (connector.isSsl()) {
sslCtx = configManager.getSslContext();
}
b.childHandler(new ServerInitializer(sslCtx, type));
ChannelFuture future;
try {
future = b.bind(connector.getSocketAddress()).sync();
} catch (Exception e) {
// https://github.com/netty/netty/issues/2597
if (e instanceof IOException) {
throw new IOException("Failed to bind to address: " + connector, e);
}
throw e;
}
future.addListener(
(ChannelFutureListener)
f -> {
if (!f.isSuccess()) {
try {
f.get();
} catch (InterruptedException | ExecutionException e) {
logger.error("", e);
}
System.exit(-1); // NO PMD
}
serverGroups.registerChannel(f.channel());
});
future.sync();
ChannelFuture f = future.channel().closeFuture();
f.addListener(
(ChannelFutureListener)
listener -> logger.info("{} model server stopped.", purpose));
logger.info("{} API bind to: {}", purpose, connector);
return f;
}