mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-16 15:58:41 +08:00
update异常后删除连接
This commit is contained in:
@@ -59,10 +59,16 @@ public class PileChannelEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void removeByPileSn(String pileSn){
|
public static void removeByPileSn(String pileSn){
|
||||||
|
if (StringUtils.isBlank(pileSn)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
manager.remove(pileSn);
|
manager.remove(pileSn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeByChannelId(String channelId){
|
public static void removeByChannelId(String channelId){
|
||||||
|
if (StringUtils.isBlank(channelId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
String pileSn = getPileSnByChannelId(channelId);
|
String pileSn = getPileSnByChannelId(channelId);
|
||||||
if (StringUtils.isNotBlank(pileSn)) {
|
if (StringUtils.isNotBlank(pileSn)) {
|
||||||
manager.remove(pileSn);
|
manager.remove(pileSn);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.jsowell.netty.server.yunkuaichong;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||||
import com.jsowell.common.util.BytesUtil;
|
import com.jsowell.common.util.BytesUtil;
|
||||||
|
import com.jsowell.common.util.StringUtils;
|
||||||
import com.jsowell.common.util.YKCUtils;
|
import com.jsowell.common.util.YKCUtils;
|
||||||
import com.jsowell.netty.service.yunkuaichong.YKCBusinessService;
|
import com.jsowell.netty.service.yunkuaichong.YKCBusinessService;
|
||||||
import io.netty.buffer.ByteBuf;
|
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);
|
log.error("Client-IP:【{}】, channelId:【{}】, pileSn:【{}】, ALL_IDLE 总超时", socketString, channelId, pileSn);
|
||||||
}
|
}
|
||||||
if (flag) {
|
if (flag) {
|
||||||
log.error("发生异常,关闭链接,channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
|
|
||||||
ctx.channel().close();
|
ctx.channel().close();
|
||||||
|
close(channelId, pileSn);
|
||||||
close(channelId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,15 +202,17 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|||||||
}
|
}
|
||||||
log.error("【{}】发生了错误, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, CHANNEL_MAP.size());
|
log.error("【{}】发生了错误, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, CHANNEL_MAP.size());
|
||||||
ctx.channel().close();
|
ctx.channel().close();
|
||||||
|
|
||||||
close(channelId);
|
|
||||||
}
|
}
|
||||||
|
close(channelId, pileSn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close(ChannelId channelId) {
|
private void close(ChannelId channelId, String pileSn) {
|
||||||
// 删除桩编号和channel的关系
|
log.error("close方法-发生异常,关闭链接,channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
|
||||||
PileChannelEntity.removeByChannelId(channelId.asLongText());
|
|
||||||
|
|
||||||
|
// 删除桩编号和channel的关系
|
||||||
|
if (StringUtils.isNotBlank(pileSn)) {
|
||||||
|
PileChannelEntity.removeByPileSn(pileSn);
|
||||||
|
}
|
||||||
// 删除连接
|
// 删除连接
|
||||||
CHANNEL_MAP.remove(channelId);
|
CHANNEL_MAP.remove(channelId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user