update异常后删除连接

This commit is contained in:
2023-11-06 14:22:58 +08:00
parent df8f916c88
commit 23e52ca90c
2 changed files with 15 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package com.jsowell.netty.server.yunkuaichong;
import com.google.common.collect.Lists;
import com.jsowell.common.enums.ykc.PileChannelEntity;
import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.service.yunkuaichong.YKCBusinessService;
import io.netty.buffer.ByteBuf;
@@ -178,10 +179,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
log.error("Client-IP:【{}】, channelId:【{}】, pileSn:【{}】, ALL_IDLE 总超时", socketString, channelId, pileSn);
}
if (flag) {
log.error("发生异常关闭链接channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
ctx.channel().close();
close(channelId);
close(channelId, pileSn);
}
}
}
@@ -203,15 +202,17 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
}
log.error("【{}】发生了错误, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, CHANNEL_MAP.size());
ctx.channel().close();
close(channelId);
}
close(channelId, pileSn);
}
private void close(ChannelId channelId) {
// 删除桩编号和channel的关系
PileChannelEntity.removeByChannelId(channelId.asLongText());
private void close(ChannelId channelId, String pileSn) {
log.error("close方法-发生异常关闭链接channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
// 删除桩编号和channel的关系
if (StringUtils.isNotBlank(pileSn)) {
PileChannelEntity.removeByPileSn(pileSn);
}
// 删除连接
CHANNEL_MAP.remove(channelId);
}