Skip to content

Commit

Permalink
Fix: Unregister client on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
HttpMarco committed Jul 14, 2024
1 parent 2852d2d commit 06e3431
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public void initialize() {
var bootstrap = new ServerBootstrap()
.group(bossGroup(), workerGroup)
.channelFactory(CommunicationNetworkUtils.generateChannelFactory())
.childHandler(new ChannelInitializer(new CommunicationTransmitHandler(it -> this.channels, (it, channel) -> channel.call(it, channel), channelTransmit -> channels.add(CommunicationServerTransmit.of(channelTransmit, this)))))
.childHandler(new ChannelInitializer(new CommunicationTransmitHandler(
(it) -> this.channels,
(it, channel) -> channel.call(it, channel),
(it) -> channels.add(CommunicationServerTransmit.of(it, this)),
(it) -> channels.removeIf(channel -> channel.channel().equals(it.channel()))
)))

// all channel options
.childOption(ChannelOption.TCP_NODELAY, true)
Expand All @@ -46,6 +51,12 @@ public void initialize() {
});
}

@Override
public void close() {
workerGroup.shutdownGracefully();
super.close();
}

@Override
public void sendPacket(Packet packet) {
this.channels.forEach(channelTransmit -> channelTransmit.sendPacket(packet));
Expand Down

0 comments on commit 06e3431

Please sign in to comment.