Example usage for io.netty.util.concurrent EventExecutorGroup shutdownGracefully

List of usage examples for io.netty.util.concurrent EventExecutorGroup shutdownGracefully

Introduction

In this page you can find the example usage for io.netty.util.concurrent EventExecutorGroup shutdownGracefully.

Prototype

Future<?> shutdownGracefully();

Source Link

Document

Shortcut method for #shutdownGracefully(long,long,TimeUnit) with sensible default values.

Usage

From source file:com.googlecode.protobuf.pro.duplex.CleanShutdownHandler.java

License:Apache License

private boolean performShutdown(long timeoutForEach) {
    boolean success = true;
    shutdownLOCK.lock();// ww  w  .ja va2 s  .co  m
    try {
        log.debug("Releasing " + watchdogs.size() + " Client Watchdogs.");
        for (RpcClientConnectionWatchdog watchdog : getWatchdogs()) {
            watchdog.stop();
        }

        log.debug("Releasing " + bootstraps.size() + " Client Bootstrap.");
        for (EventExecutorGroup bootstrap : getBootstraps()) {
            bootstrap.shutdownGracefully();
        }

        log.debug("Releasing " + executors.size() + " Executors.");
        for (ExecutorService executor : getExecutors()) {
            executor.shutdown();
        }

        if (timeoutForEach > 0) {
            for (EventExecutorGroup bootstrap : getBootstraps()) {
                try {
                    if (!bootstrap.awaitTermination(timeoutForEach, TimeUnit.MILLISECONDS)) {
                        success = false;
                    }
                } catch (InterruptedException e) {
                    success = false;
                }
            }
            for (ExecutorService executor : getExecutors()) {
                try {
                    if (!executor.awaitTermination(timeoutForEach, TimeUnit.MILLISECONDS)) {
                        success = false;
                    }
                } catch (InterruptedException e) {
                    success = false;
                }
            }
        }
    } finally {
        shutdownLOCK.unlock();
    }

    // if it is not the shutdown thread shutting down the jvm then we need to remove the
    // shutdown hook
    if (Thread.currentThread() != shutdownThread) {
        Runtime.getRuntime().removeShutdownHook(shutdownThread);
    }
    return success;
}

From source file:net.dongliu.prettypb.rpc.utils.CleanShutdownHandler.java

License:Apache License

public CleanShutdownHandler() {
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        log.debug("Releasing " + bootstraps.size() + " Client Bootstrap.");
        for (EventExecutorGroup bootstrap : getBootstraps()) {
            bootstrap.shutdownGracefully();
        }//from w  ww  .j  a  v a 2  s  . c o  m

        log.debug("Releasing " + executors.size() + " Executors.");
        for (ExecutorService executor : getExecutors()) {
            executor.shutdown();
        }
    }));
}

From source file:org.jooby.internal.netty.NettyServer.java

License:Apache License

/**
 * Shutdown executor in order./* www .  ja  va  2  s.  c  om*/
 *
 * @param iterator Executors to shutdown.
 */
private void shutdownGracefully(final Iterator<EventExecutorGroup> iterator) {
    if (iterator.hasNext()) {
        EventExecutorGroup group = iterator.next();
        if (!group.isShuttingDown()) {
            group.shutdownGracefully().addListener(future -> {
                if (!future.isSuccess()) {
                    log.debug("shutdown of {} resulted in exception", group, future.cause());
                }
                shutdownGracefully(iterator);
            });
        }
    }
}