mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-07-03 13:38:02 +08:00
update异常后删除连接
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.jsowell.common.enums.ykc;
|
package com.jsowell.common.enums.ykc;
|
||||||
|
|
||||||
|
import com.jsowell.common.util.StringUtils;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@@ -61,4 +62,11 @@ public class PileChannelEntity {
|
|||||||
manager.remove(pileSn);
|
manager.remove(pileSn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removeByChannelId(String channelId){
|
||||||
|
String pileSn = getPileSnByChannelId(channelId);
|
||||||
|
if (StringUtils.isNotBlank(pileSn)) {
|
||||||
|
manager.remove(pileSn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -180,6 +180,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
|||||||
if (flag) {
|
if (flag) {
|
||||||
log.error("发生异常,关闭链接,channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
|
log.error("发生异常,关闭链接,channelId:{}, pileSn:{}", channelId.asShortText(), pileSn);
|
||||||
ctx.channel().close();
|
ctx.channel().close();
|
||||||
|
|
||||||
|
close(channelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,6 +203,16 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void close(ChannelId channelId) {
|
||||||
|
// 删除桩编号和channel的关系
|
||||||
|
PileChannelEntity.removeByChannelId(channelId.asLongText());
|
||||||
|
|
||||||
|
// 删除连接
|
||||||
|
CHANNEL_MAP.remove(channelId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user