Example usage for io.netty.channel EventLoopGroup terminationFuture

List of usage examples for io.netty.channel EventLoopGroup terminationFuture

Introduction

In this page you can find the example usage for io.netty.channel EventLoopGroup terminationFuture.

Prototype

Future<?> terminationFuture();

Source Link

Document

Returns the Future which is notified when all EventExecutor s managed by this EventExecutorGroup have been terminated.

Usage

From source file:org.dcache.xrootd.standalone.DataServer.java

License:Open Source License

public void start() throws InterruptedException {
    final EventLoopGroup bossGroup;
    final EventLoopGroup workerGroup;
    Class<? extends ServerSocketChannel> channelClass;
    if (_configuration.useBlockingIo) {
        bossGroup = new OioEventLoopGroup();
        workerGroup = new OioEventLoopGroup();
        channelClass = OioServerSocketChannel.class;
    } else {//from  w  w w  .  j av  a2s .  c  o  m
        bossGroup = new NioEventLoopGroup();
        workerGroup = new NioEventLoopGroup();
        channelClass = NioServerSocketChannel.class;
    }
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            // Shut down all event loops to terminate all threads.
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();

            try {
                // Wait until all threads are terminated.
                bossGroup.terminationFuture().sync();
                workerGroup.terminationFuture().sync();
            } catch (InterruptedException ignored) {
            }
        }
    });
    ServerBootstrap bootstrap = new ServerBootstrap().group(bossGroup, workerGroup).channel(channelClass)
            .localAddress(_configuration.port).childOption(ChannelOption.TCP_NODELAY, true)
            .childOption(ChannelOption.SO_KEEPALIVE, true)
            .childHandler(new DataServerChannelInitializer(_configuration));

    bootstrap.bind().sync().channel().closeFuture().sync();
}

From source file:org.vootoo.server.netty.SolrNettyServer.java

License:Apache License

protected void startNetty() throws Exception {
    logger.info("netty server starting port={} ...", port);
    queryExecutor = new RequestExecutor(queryConfig);
    updateExecutor = new RequestExecutor(updateConfig);

    EventLoopGroup bossGroup = new NioEventLoopGroup(bossWorkerNum);
    EventLoopGroup workerGroup = new NioEventLoopGroup(ioWorkerNum);
    try {/*from  w ww.  j ava  2 s .co  m*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SolrServerChannelInitializer(
                        coreContainer, handlerConfigs, queryExecutor, updateExecutor));

        // Start the server.
        ChannelFuture f = b.bind(port).sync();

        logger.info("netty server started port={}", port);

        // Wait until the server socket is closed.
        serverChannel = f.channel();
        serverChannel.closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();

        // Wait until all threads are terminated.
        bossGroup.terminationFuture().sync();
        workerGroup.terminationFuture().sync();
    }
}

From source file:snow.http.server.HttpServer.java

License:Open Source License

private static void run(int port) throws Throwable {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*from w ww .j  a  v  a  2  s . c  o m*/
        new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new Initializer()).bind(port).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
        bossGroup.terminationFuture().sync();
        workerGroup.terminationFuture().sync();
    }
}