Example usage for io.netty.channel.group ChannelGroupFuture await

List of usage examples for io.netty.channel.group ChannelGroupFuture await

Introduction

In this page you can find the example usage for io.netty.channel.group ChannelGroupFuture await.

Prototype

@Override
    ChannelGroupFuture await() throws InterruptedException;

Source Link

Usage

From source file:com.ghrum.common.protocol.CommonConnectionManager.java

License:Apache License

/**
 * Stop the primary channel and all connected channels
 *
 * @param reason the reason for disconnection
 *//*from w w w.j  a  v  a2  s  .  c o  m*/
public void stop(String reason) {
    // Disconnect all connections that are connected
    // to our channel, sending the kick message
    disconnect(reason);

    // Disconnect all connection that were left behind
    // and stop the Netty workers
    ChannelGroupFuture f = group.close();
    try {
        f.await();
    } catch (InterruptedException ex) {
        // <TODO: Wolftein Use some common logger>
    }
    bossGroup.shutdownGracefully();
    workerGroup.shutdownGracefully();
}

From source file:com.trinity.engine.protocol.detail.TrinityConnectionManager.java

License:Apache License

/**
 * Stops the connection manager and disconnect all connections
 *
 * @param reason the reason for disconnection
 *//* w  ww .  j  a  v  a 2 s  .com*/
public void stop(String reason) {
    // Disconnect all connections from the main
    // channel of the manager
    disconnect(reason);

    // Disconnect the main channel of the manager
    final ChannelGroupFuture future = mGroup.close();
    try {
        future.await();
    } catch (InterruptedException exception) {
        getUncaughtExceptionHandler().uncaughtException(exception);
    }
    mBossGroup.shutdownGracefully();
    mWorkerGroup.shutdownGracefully();
}

From source file:org.spout.engine.SpoutServer.java

License:Open Source License

@Override
public boolean stop(final String message, boolean stopScheduler) {
    if (!super.stop(message, false)) {
        return false;
    }/*  w ww. j  av a  2s  .  c  om*/
    final SpoutServer engine = this;
    Runnable lastTickTask = new Runnable() {
        @Override
        public void run() {
            EngineStopEvent stopEvent = new EngineStopEvent(message);
            getEventManager().callEvent(stopEvent);
            for (Player player : getOnlinePlayers()) {
                ((SpoutPlayer) player).kick(true, stopEvent.getMessage());
            }
            if (upnpService != null) {
                upnpService.shutdown();
            }
            closeBonjour();
            for (SpoutWorld world : engine.getLiveWorlds()) {
                world.unload(true);
            }
        }
    };

    Runnable finalTask = new Runnable() {
        @Override
        public void run() {
            ChannelGroupFuture f = group.close();
            try {
                f.await();
            } catch (InterruptedException ie) {
                getLogger().info("Thread interrupted when waiting for network shutdown");
            }
            WorldSavingThread.finish();
            WorldSavingThread.staticJoin();

            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
            boundProtocols.clear();
        }
    };

    getScheduler().submitLastTickTask(lastTickTask);
    getScheduler().submitFinalTask(finalTask, false);
    getScheduler().stop();
    return true;
}