WebAppServer.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:kha 作者:
public void start() {
        apiBootstrap = new ServerBootstrap();
        ThreadFactory threadFactory = new NamedThreadFactory("kha-webapp");
        EventLoopGroup commonGroup = new OioEventLoopGroup(0, threadFactory);
        try {
            // the hub will only have a few connections, so OIO is likely to be faster than NIO in this case!
            apiBootstrap.group(commonGroup, commonGroup)
                    .channel(OioServerSocketChannel.class)
                    .localAddress(port)
                    .childOption(ChannelOption.SO_KEEPALIVE, true)
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        protected void initChannel(SocketChannel ch) throws Exception {
                            ChannelPipeline pipeline = ch.pipeline();

                            pipeline.addLast("http-request-decoder", new HttpRequestDecoder());
                            pipeline.addLast("http-object-aggregator", new HttpObjectAggregator(1048576));
                            pipeline.addLast("http-response-encoder", new HttpResponseEncoder());
//                            pipeline.addLast("deflater", new HttpContentDecompressor());
//                            pipeline.addLast("inflater", new HttpContentCompressor());
                            pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
                            pipeline.addLast("cors", new CorsHandler(corsConfig));
                            pipeline.addLast("file-handler", new HttpStaticFileServerHandler(hubSiteDirectory, true));
                        }
                    });

            ChannelFuture f = apiBootstrap.bind().sync();
            LOGGER.info("WebApp available on http://{}:{}", InetAddress.getLocalHost().getCanonicalHostName(), port);
            f.channel().closeFuture().sync();
        } catch (Exception e) {
            LOGGER.error("Can't start WebApp server", e);
        }
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号