Search in sources :

Example 1 with NettyRpcChannelInitializer

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

the class NettyRpcServer 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 NettyRpcChannelInitializer(invokerFactory, serializer, filters));
    bootstrap.childOption(ChannelOption.SO_REUSEADDR, true);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    channel = bootstrap.bind(inet).sync().channel();
    System.out.println("TurboRpcServer started. Listening on: " + hostPort);
}
Also used : 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) NettyRpcChannelInitializer(rpc.turbo.transport.server.rpc.handler.NettyRpcChannelInitializer)

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 NettyRpcChannelInitializer (rpc.turbo.transport.server.rpc.handler.NettyRpcChannelInitializer)1