Example usage for io.netty.bootstrap ServerBootstrap childHandler

List of usage examples for io.netty.bootstrap ServerBootstrap childHandler

Introduction

In this page you can find the example usage for io.netty.bootstrap ServerBootstrap childHandler.

Prototype

ChannelHandler childHandler

To view the source code for io.netty.bootstrap ServerBootstrap childHandler.

Click Source Link

Usage

From source file:playground.gregor.vis.VisServer.java

License:Open Source License

private void initServer() {

    PeerInfo server = new PeerInfo("localhost", 9090);

    RpcServerCallExecutor executor = new ThreadPoolCallExecutor(3, 200);

    DuplexTcpServerPipelineFactory serverFactory = new DuplexTcpServerPipelineFactory(server);
    serverFactory.setRpcServerCallExecutor(executor);

    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(// w ww . j  av  a 2  s. c o  m
            new NioEventLoopGroup(0, new RenamingThreadFactoryProxy("boss", Executors.defaultThreadFactory())),
            new NioEventLoopGroup(0,
                    new RenamingThreadFactoryProxy("worker", Executors.defaultThreadFactory())));
    bootstrap.channel(NioServerSocketChannel.class);
    bootstrap.childHandler(serverFactory);
    bootstrap.localAddress(server.getPort());
    bootstrap.option(ChannelOption.SO_SNDBUF, 1048576);
    bootstrap.option(ChannelOption.SO_RCVBUF, 1048576);
    bootstrap.childOption(ChannelOption.SO_RCVBUF, 1048576);
    bootstrap.childOption(ChannelOption.SO_SNDBUF, 1048576);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);

    serverFactory.getRpcServiceRegistry()
            .registerService(ProtoFrame.FrameServerService.newReflectiveBlockingService(this.service));

    bootstrap.bind();

}

From source file:reactor.ipc.netty.tcp.TcpServer.java

License:Open Source License

@Override
public final Mono<? extends NettyContext> newHandler(
        BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler) {
    Objects.requireNonNull(handler, "handler");
    return Mono.create(sink -> {
        ServerBootstrap b = options.get();
        ContextHandler<Channel> contextHandler = doHandler(handler, sink);
        b.childHandler(contextHandler);
        if (log.isDebugEnabled()) {
            b.handler(loggingHandler());
        }//from   w  w w  . j  a  v  a  2s .  c o m
        contextHandler.setFuture(b.bind());
    });
}

From source file:sailfish.remoting.DefaultServer.java

License:Apache License

public void start() throws SailfishException {
    ServerBootstrap boot = newServerBootstrap();
    EventLoopGroup accept = NettyPlatformIndependent.newEventLoopGroup(1,
            new DefaultThreadFactory(RemotingConstants.SERVER_ACCEPT_THREADNAME));
    if (null != config.getEventLoopGroup()) {
        boot.group(accept, config.getEventLoopGroup());
    } else {/* w w  w . j av  a2 s . c o  m*/
        boot.group(accept, ServerEventGroup.INSTANCE.getLoopGroup());
    }
    final EventExecutorGroup executor = (null != config.getEventExecutorGroup() ? config.getEventExecutorGroup()
            : ServerEventGroup.INSTANCE.getExecutorGroup());
    boot.localAddress(config.address().host(), config.address().port());
    boot.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            ch.attr(ChannelAttrKeys.OneTime.idleTimeout).set(config.idleTimeout());
            ch.attr(ChannelAttrKeys.maxIdleTimeout).set(config.maxIdleTimeout());
            ch.attr(ChannelAttrKeys.exchangeServer).set(DefaultServer.this);
            pipeline.addLast(executor, RemotingEncoder.INSTANCE, new RemotingDecoder(),
                    new IdleStateHandler(config.idleTimeout(), 0, 0), HeartbeatChannelHandler.INSTANCE,
                    NegotiateChannelHandler.INSTANCE, ConcreteRequestHandler.INSTANCE);
        }
    });
    try {
        channel = boot.bind().syncUninterruptibly().channel();
    } catch (Throwable cause) {
        throw new SailfishException(cause);
    }
}