Search in sources :

Example 1 with ServerShutdownHook

use of com.nike.riposte.server.hooks.ServerShutdownHook in project riposte by Nike-Inc.

the class Server method shutdown.

public void shutdown() throws InterruptedException {
    try {
        logger.info("Shutting down Riposte...");
        List<ChannelFuture> channelCloseFutures = new ArrayList<>();
        for (Channel ch : channels) {
            // execute shutdown hooks
            if (serverConfig.serverShutdownHooks() != null) {
                for (ServerShutdownHook hook : serverConfig.serverShutdownHooks()) {
                    hook.executeServerShutdownHook(serverConfig, ch);
                }
            }
            channelCloseFutures.add(ch.close());
        }
        for (ChannelFuture chf : channelCloseFutures) {
            chf.sync();
        }
    } finally {
        eventLoopGroups.forEach(EventExecutorGroup::shutdownGracefully);
        logger.info("...Riposte shutdown complete");
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) ServerShutdownHook(com.nike.riposte.server.hooks.ServerShutdownHook)

Aggregations

ServerShutdownHook (com.nike.riposte.server.hooks.ServerShutdownHook)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ServerChannel (io.netty.channel.ServerChannel)1 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)1 ArrayList (java.util.ArrayList)1