Search in sources :

Example 1 with NettyRestChannelInitializer

use of rpc.turbo.transport.server.rest.handler.NettyRestChannelInitializer in project turbo-rpc by hank-whu.

the class NettyRestServer method start.

public void start() throws InterruptedException {
    InetSocketAddress inet = new InetSocketAddress(hostPort.host, hostPort.port);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(eventLoopGroup);
    bootstrap.option(ChannelOption.SO_BACKLOG, 256);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    if (eventLoopGroup instanceof EpollEventLoopGroup) {
        bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
        bootstrap.channel(EpollServerSocketChannel.class);
    } else if (eventLoopGroup instanceof NioEventLoopGroup) {
        bootstrap.channel(NioServerSocketChannel.class);
    }
    bootstrap.childHandler(new NettyRestChannelInitializer(invokerFactory, jsonMapper, filters));
    bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    channel = bootstrap.bind(inet).sync().channel();
    System.out.println("NettyRestServer started. Listening on: " + hostPort);
}
Also used : NettyRestChannelInitializer(rpc.turbo.transport.server.rest.handler.NettyRestChannelInitializer) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 InetSocketAddress (java.net.InetSocketAddress)1 NettyRestChannelInitializer (rpc.turbo.transport.server.rest.handler.NettyRestChannelInitializer)1