diff --git a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileChannelEntity.java b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileChannelEntity.java index d51604c02..b0d7924bf 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileChannelEntity.java +++ b/jsowell-common/src/main/java/com/jsowell/common/enums/ykc/PileChannelEntity.java @@ -114,6 +114,12 @@ public class PileChannelEntity { return null; } + // public static String getPileSnByCtx(ChannelHandlerContext ctx) { + // for (HashMap.Entry entry : manager.entrySet()) { + // + // } + // } + /** * 打印 */ diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java index c1515f446..f9df62675 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java +++ b/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java @@ -213,6 +213,8 @@ public class YKCUtils { // 保存桩号和channel的关系 PileChannelEntity.checkChannel(pileSn, ctx); + + PileChannelEntity.checkChannelV2(pileSn, ctx); } /** diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java index ce1bd6964..a259fba02 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/server/yunkuaichong/NettyServerHandler.java @@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.net.InetSocketAddress; +import java.util.Collection; import java.util.List; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; @@ -149,8 +150,10 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { // 响应客户端 ByteBuf buffer = ctx.alloc().buffer().writeBytes(response); this.channelWrite(channel.id(), buffer); + // 获取桩号 + String pileSn = PileChannelEntity.getPileSnByChannelId(ctx.channel().id().asLongText()); // 批量响应客户端 - // this.channelWriteBatch(ctx, buffer); + this.channelWriteBatch(pileSn, buffer); if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) { // 应答帧类型 byte[] responseFrameTypeBytes = YKCFrameTypeCode.PlatformAnswersRelation.getResponseFrameTypeBytes(frameTypeBytes); @@ -172,7 +175,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { * @param ctx * @param msg */ - private void channelWriteBatch(String pileSn, ChannelHandlerContext ctx, Object msg) { + private void channelWriteBatch(String pileSn, Object msg) { // 获取该桩下的所有channel List list = PileChannelEntity.pileMap.get(pileSn); if(CollectionUtils.isEmpty(list)) { @@ -304,7 +307,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { } log.error("【{}】发生了错误, pileSn:【{}】此连接被关闭, 此时连通数量: {}", channelId, pileSn, CHANNEL_MAP.size()); // 删除连接 - // PileChannelEntity.deleteChannel(pileSn, ctx); + PileChannelEntity.deleteChannel(pileSn, ctx); ctx.channel().close(); } } finally { diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCBusinessServiceImpl.java b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCBusinessServiceImpl.java index 6dc28ffec..c5be569bf 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCBusinessServiceImpl.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/service/yunkuaichong/impl/YKCBusinessServiceImpl.java @@ -88,7 +88,7 @@ public class YKCBusinessServiceImpl implements YKCBusinessService { pileMsgRecordService.save(pileSn, pileSn, type, jsonMsg, ""); // 删除连接 - // PileChannelEntity.deleteChannel(pileSn, ctx); + PileChannelEntity.deleteChannel(pileSn, ctx); // 删除桩编号和channel的关系 // PileChannelEntity.removeByPileSn(pileSn); diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java index 24aa11377..3787221f1 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/YKCPushCommandServiceImpl.java @@ -126,14 +126,14 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService { log.error("push发送命令失败, pileSn:{}", pileSn, cause); // 异步删除Map中的保存关系(带关闭连接) - // CompletableFuture.runAsync(() -> { - // try { - // // 删除Map中的保存关系 - // PileChannelEntity.deleteChannel(pileSn, ctx); - // } catch (Exception e) { - // log.error("异步删除、关闭连接 error", e); - // } - // }, executor); + CompletableFuture.runAsync(() -> { + try { + // 删除Map中的保存关系 + PileChannelEntity.deleteChannel(pileSn, ctx); + } catch (Exception e) { + log.error("异步删除、关闭连接 error", e); + } + }, executor); } }); @@ -231,14 +231,14 @@ public class YKCPushCommandServiceImpl implements YKCPushCommandService { log.error("push发送命令失败, pileSn:{}", pileSn, cause); // 异步删除Map中的保存关系(带关闭连接) - // CompletableFuture.runAsync(() -> { - // try { - // // 删除Map中的保存关系 - // PileChannelEntity.deleteChannel(pileSn, ctx); - // } catch (Exception e) { - // log.error("异步删除、关闭连接 error", e); - // } - // }, executor); + CompletableFuture.runAsync(() -> { + try { + // 删除Map中的保存关系 + PileChannelEntity.deleteChannel(pileSn, ctx); + } catch (Exception e) { + log.error("异步删除、关闭连接 error", e); + } + }, executor); } });