Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/main/java/ru/wildbot/wildbotcore/server/NettyServerCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
}