diff --git a/src/main/java/ru/wildbot/wildbotcore/server/NettyServerCore.java b/src/main/java/ru/wildbot/wildbotcore/server/NettyServerCore.java index ed021ed..e243d26 100644 --- a/src/main/java/ru/wildbot/wildbotcore/server/NettyServerCore.java +++ b/src/main/java/ru/wildbot/wildbotcore/server/NettyServerCore.java @@ -206,6 +206,8 @@ import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.DefaultChannelPromise; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import lombok.val; @@ -244,15 +246,18 @@ public void start(String name, final ServerBootstrap bootstrap, int port) throws Tracer.info("Netty Channel for name `" + name + "` has been successfully started"); } + @SuppressWarnings("uncheked") public void shutdown() { childGroup.shutdownGracefully(); parentGroup.shutdownGracefully(); // Closing all channels existing - for (val channel : channels.values()) try { - channel.channel().closeFuture().sync(); - } catch (InterruptedException e) { - Tracer.error("An exception occurred while trying to stop Netty-Server. Aborting"); - } + for (val channel : channels.values()) + try { + channel.channel().close().addListener((ChannelFutureListener) channelFuture -> + Tracer.info("Closed channel " + channel)).awaitUninterruptibly(); + } catch (InterruptedException e) { + Tracer.error("An exception occurred while trying to stop Netty-Server. Aborting"); + } } }