| | |
| | | return bootstrap; |
| | | } |
| | | |
| | | /** 新增或重连服务器 */ |
| | | /** |
| | | * 新增或重连服务器 |
| | | */ |
| | | public void connectServer(ArdServerInfo serverInfo) { |
| | | String serverId = serverInfo.getId(); |
| | | String host = serverInfo.getHost(); |
| | |
| | | Channel channel = f.channel(); |
| | | channel.attr(AttributeKey.valueOf("serverId")).set(serverId); |
| | | TyTcpServerCache.putTcpServerCache(serverId, true); |
| | | // 断开服务器,修改状态为: 0 - 在线 |
| | | ardServerService.updateServerStatus(serverId, "1"); |
| | | } else { |
| | | log.warn("❌ 服务器 [{}] 连接失败", serverId); |
| | | TyTcpServerCache.putTcpServerCache(serverId, false); |
| | | // 断开服务器,修改状态为: 0 - 离线 |
| | | ardServerService.updateServerStatus(serverId, "0"); |
| | | } |
| | | }); |
| | | |
| | |
| | | channels.put(serverId, session); |
| | | } |
| | | |
| | | /** 断开服务器连接 */ |
| | | /** |
| | | * 断开服务器连接 |
| | | */ |
| | | public void disconnectServer(String serverId) { |
| | | TcpClientSession session = channels.remove(serverId); |
| | | if (session != null && session.getChannelFuture() != null) { |
| | | session.getChannelFuture().channel().close(); |
| | | log.info("断开服务器 [{}] 连接", serverId); |
| | | // 断开服务器,修改状态为: 0 - 离线 |
| | | ardServerService.updateServerStatus(serverId, "0"); |
| | | } |
| | | TyTcpServerCache.removeTcpServerCache(serverId); |
| | | } |
| | |
| | | @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; |
| | |
| | | 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); |
| | | } |
| | |
| | | session.getServerId(), session.getHost(), session.getPort(), timestamp); |
| | | }); |
| | | } |
| | | |
| | | } |