Search in sources :

Example 1 with NioSocketChannel

use of io.netty.channel.socket.nio.NioSocketChannel in project rest.li by linkedin.

the class HttpNettyServer method start.

@Override
public void start() {
    _eventExecutors = new DefaultEventExecutorGroup(_threadPoolSize);
    _bossGroup = new NioEventLoopGroup(1, new NamedThreadFactory("R2 Nio Boss"));
    _workerGroup = new NioEventLoopGroup(0, new NamedThreadFactory("R2 Nio Worker"));
    ServerBootstrap bootstrap = new ServerBootstrap().group(_bossGroup, _workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<NioSocketChannel>() {

        @Override
        protected void initChannel(NioSocketChannel ch) throws Exception {
            ch.pipeline().addLast("decoder", new HttpRequestDecoder());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(1048576));
            ch.pipeline().addLast("encoder", new HttpResponseEncoder());
            ch.pipeline().addLast("rapi", new RAPServerCodec());
            ch.pipeline().addLast(_eventExecutors, "handler", _restOverStream ? new StreamHandler() : new RestHandler());
        }
    });
    bootstrap.bind(new InetSocketAddress(_port));
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) NamedThreadFactory(com.linkedin.r2.util.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

NamedThreadFactory (com.linkedin.r2.util.NamedThreadFactory)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)1 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)1 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)1 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)1 InetSocketAddress (java.net.InetSocketAddress)1