private ServerBootstrap createBootstrap ( final ChannelGroup channelGroup ) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup ( bossThreadPoolSize , createDaemonThreadFactory ( serviceName + "-boss-thread-%d" ) ) ; EventLoopGroup workerGroup = new NioEventLoopGroup ( workerThreadPoolSize , createDaemonThreadFactory ( serviceName + "-worker-thread-%d" ) ) ; ServerBootstrap bootstrap = new ServerBootstrap ( ) ; bootstrap . group ( bossGroup , workerGroup ) . channel ( NioServerSocketChannel . class ) . childHandler ( new ChannelInitializer < SocketChannel > ( ) { @ Override protected void initChannel ( SocketChannel ch ) throws Exception { channelGroup . add ( ch ) ; ChannelPipeline pipeline = ch . pipeline ( ) ; if ( sslHandlerFactory != null ) { // Add SSLHandler if SSL is enabled pipeline . addLast ( "ssl" , sslHandlerFactory . create ( ch . alloc ( ) ) ) ; } pipeline . addLast ( "codec" , new HttpServerCodec ( ) ) ; pipeline . addLast ( "compressor" , new HttpContentCompressor ( ) ) ; pipeline . addLast ( "chunkedWriter" , new ChunkedWriteHandler ( ) ) ; pipeline . addLast ( "keepAlive" , new HttpServerKeepAliveHandler ( ) ) ; pipeline . addLast ( "router" , new RequestRouter ( resourceHandler , httpChunkLimit , sslHandlerFactory != null ) ) ; if ( eventExecutorGroup == null ) { pipeline . addLast ( "dispatcher" , new HttpDispatcher ( ) ) ; } else { pipeline . addLast ( eventExecutorGroup , "dispatcher" , new HttpDispatcher ( ) ) ; } if ( pipelineModifier != null ) { pipelineModifier . modify ( pipeline ) ; } } } ) ; for ( Map . Entry < ChannelOption , Object > entry : channelConfigs . entrySet ( ) ) { bootstrap . option ( entry . getKey ( ) , entry . getValue ( ) ) ; } for ( Map . Entry < ChannelOption , Object > entry : childChannelConfigs . entrySet ( ) ) { bootstrap . childOption ( entry . getKey ( ) , entry . getValue ( ) ) ; } return bootstrap ; }
Creates the server bootstrap .