From fe63fd580c5b65fa398dfe1fdf44466b26c6aadd Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Sat, 22 Mar 2025 13:38:30 +0800
Subject: [PATCH] 优化

---
 ard-work/src/main/java/com/ard/tianyu/component/netty/NettyTcpClient.java |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/tianyu/component/netty/TyNettyTcpClient.java b/ard-work/src/main/java/com/ard/tianyu/component/netty/NettyTcpClient.java
similarity index 84%
rename from ard-work/src/main/java/com/ard/tianyu/component/netty/TyNettyTcpClient.java
rename to ard-work/src/main/java/com/ard/tianyu/component/netty/NettyTcpClient.java
index cf88289..326c5b5 100644
--- a/ard-work/src/main/java/com/ard/tianyu/component/netty/TyNettyTcpClient.java
+++ b/ard-work/src/main/java/com/ard/tianyu/component/netty/NettyTcpClient.java
@@ -21,9 +21,9 @@
 
 @Component
 @Slf4j
-public class TyNettyTcpClient {
+public class NettyTcpClient {
 
-    public static Map<String, TyBoxSession> channels = new HashMap<>();
+    public static Map<String, TcpClientSession> channels = new HashMap<>();
 
     EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
 
@@ -59,11 +59,11 @@
      */
     public void initConnection(String host, Integer port) {
 
-        log.info("初始化连接天宇tcp服务器【{}:{}】", host, port);
-        String currentBoxSn = "";
+        log.info("初始化连接TCP服务器【{}:{}】", host, port);
+        String clientId = "clientId_1";
         //判断是否已经存在连接,如果存在则关闭之前的连接
         if (channels.containsKey(host + ":" + port)) {
-            currentBoxSn = channels.get(host + ":" + port).getSubBoxSn();
+            clientId = channels.get(host + ":" + port).getClientId();
             channels.get(host + ":" + port).getChannelFuture().channel().close();
         }
 
@@ -71,12 +71,12 @@
         Bootstrap bootstrap = getBootstrap();
         ChannelFuture future = bootstrap.connect(host, port).addListener((ChannelFuture futureListener) -> {
             if (futureListener.isSuccess()) {
-                log.info("连接天宇TCP服务器成功【{}:{}】", host, port);
+                log.info("连接TCP服务器成功【{}:{}】", host, port);
                 TyTcpServerCache.putTcpServerCache(host + ":" + port, true);
             } else {
                 final EventLoop eventLoop = futureListener.channel().eventLoop();
                 eventLoop.schedule(() -> {
-                    log.info("连接天宇TCP服务器失败【{}:{}】,正尝试重连...", host, port);
+                    log.info("连接TCP服务器失败【{}:{}】,正尝试重连...", host, port);
                     TyTcpServerCache.putTcpServerCache(host + ":" + port, false);
                     try {
                         initConnection(host, port);
@@ -87,7 +87,8 @@
             }
         });
         //将连接存入集合
-        channels.put(host + ":" + port, TyBoxSession.builder().subBoxSn(currentBoxSn).channelFuture(future).isReConnect(!currentBoxSn.equals("")).build());
+        channels.put(host + ":" + port,
+                TcpClientSession.builder().ClientId(clientId).channelFuture(future).isReConnect(!clientId.isEmpty()).build());
     }
 
     //创建天宇连接

--
Gitblit v1.9.3