public class HttpServer {
private static final Logger logger = LogManager.getLogger("default");
public static void main(String[] args) throws InterruptedException, IOException {
try {
MetricKafkaHttpServer server = new MetricKafkaHttpServer();
server.run();
} finally {
logger.error("Server shutting down.");
}
}
public void run() throws InterruptedException {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(workerGroup, bossGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline()
.addLast("inboundDecoder", new HttpRequestDecoder())
.addLast("outboundEncoder", new HttpResponseEncoder()) // 1
.addLast("inboundAggregator", new HttpObjectAggregator(50 * 1024 * 1024))
.addLast("inboundHandler", new HttpRequestHandler());
}
})
//TODO options
.option(ChannelOption.SO_BACKLOG, 1024)
.childOption(ChannelOption.SO_KEEPALIVE, true); // 2
ChannelFuture f = b.bind(ServerProperties.PORT).sync();
logger.info("Server started in port " + ServerProperties.PORT + ".");
f.channel().closeFuture().sync();
} finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
}
}
}public class HttpServer {
private static fi