公共方法 关闭连接

This commit is contained in:
2023-12-06 14:31:21 +08:00
parent 33f33778bd
commit f249184cfe

View File

@@ -208,14 +208,20 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
// close(channelId, pileSn);
}
private void close(ChannelId channelId, String pileSn, ChannelHandlerContext ctx) {
log.error("close方法-发生异常关闭链接channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
// 公共方法 关闭连接
private void closeConnection(String pileSn, ChannelHandlerContext ctx) {
Channel channel = ctx.channel();
ChannelId channelId = channel.id();
log.error("close方法-发生异常关闭链接channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
if (channel != null && !channel.isActive() && !channel.isOpen() && !channel.isWritable()) {
channel.close();
// 删除连接
CHANNEL_MAP.remove(channelId);
}
// 删除桩编号和channel的关系
if (StringUtils.isNotBlank(pileSn)) {
// PileChannelEntity.removeByPileSn(pileSn);
PileChannelEntity.removeByPileSn(pileSn);
}
// 删除连接
CHANNEL_MAP.remove(channelId);
}
}