From dd81d932a833209ec2067f7179f7dd1ae97b2d56 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Thu, 16 Oct 2025 14:39:24 +0800
Subject: [PATCH] 优化
---
ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java b/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
index 7fbf709..c3635c3 100644
--- a/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
+++ b/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
@@ -7,7 +7,7 @@
import com.ard.work.component.netty.handler.MessageProtocolEncoder;
import com.ard.work.domain.cache.TyTcpServerCache;
import com.ard.work.domain.entity.ArdServerInfo;
-import com.ard.work.service.IArdServerService;
+import com.ard.work.service.IArdServerInfoService;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
@@ -36,7 +36,7 @@
private final EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
@Resource
- private IArdServerService ardServerService; // ← 从数据库读取边缘服务器配置
+ private IArdServerInfoService ardServerService; // ← 从数据库读取边缘服务器配置
@Resource
private ClientHandler clientHandler;
@@ -63,7 +63,9 @@
return bootstrap;
}
- /** 新增或重连服务器 */
+ /**
+ * 新增或重连服务器
+ */
public void connectServer(ArdServerInfo serverInfo) {
String serverId = serverInfo.getId();
String host = serverInfo.getHost();
@@ -97,7 +99,9 @@
channels.put(serverId, session);
}
- /** 断开服务器连接 */
+ /**
+ * 断开服务器连接
+ */
public void disconnectServer(String serverId) {
TcpClientSession session = channels.remove(serverId);
if (session != null && session.getChannelFuture() != null) {
@@ -140,7 +144,7 @@
@PostConstruct
public void initConnectServers() {
try {
- var serverList = ardServerService.selectArdServerManagementList(new ArdServerInfo()); // ← 从数据库查询所有服务器配置
+ var serverList = ardServerService.selectArdServerInfoList(new ArdServerInfo()); // ← 从数据库查询所有服务器配置
if (serverList == null || serverList.isEmpty()) {
log.warn("未在数据库中找到边缘服务器配置,跳过连接初始化");
return;
@@ -160,7 +164,7 @@
public void reconnectFailedServers() {
TyTcpServerCache.getTcpServerCacheMap().forEach((key, state) -> {
if (Boolean.FALSE.equals(state)) { // 连接失败的服务器
- ArdServerInfo serverInfo = ardServerService.selectArdServerManagementById(key);
+ ArdServerInfo serverInfo = ardServerService.selectArdServerInfoById(key);
if (serverInfo != null) {
connectServer(serverInfo);
}
@@ -188,5 +192,4 @@
session.getServerId(), session.getHost(), session.getPort(), timestamp);
});
}
-
}
--
Gitblit v1.9.3