netty优化

This commit is contained in:
2025-08-11 09:40:01 +08:00
parent df83f65328
commit c73e062109

View File

@@ -0,0 +1,169 @@
package com.njcn.gather.detection.util.socket.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* Socket连接配置管理类
* 定义哪些requestId需要建立通道连接以及IP/PORT配置
*
* @Author: hongawen
* @Date: 2024/12/10
*/
@Component
@ConfigurationProperties(prefix = "socket")
public class SocketConnectionConfig {
/**
* 程控源设备配置
*/
private SourceConfig source = new SourceConfig();
/**
* 被检设备配置
*/
private DeviceConfig device = new DeviceConfig();
@Data
public static class SourceConfig {
/**
* 程控源IP地址
*/
private String ip;
/**
* 程控源端口号
*/
private Integer port;
}
@Data
public static class DeviceConfig {
/**
* 被检设备IP地址
*/
private String ip;
/**
* 被检设备端口号
*/
private Integer port;
}
/**
* 获取程控源配置
*/
public SourceConfig getSource() {
return source;
}
/**
* 获取被检设备配置
*/
public DeviceConfig getDevice() {
return device;
}
/**
* 需要建立程控源通道的requestId集合
* 这些requestId在发送消息时如果程控源通道不存在会自动建立连接
*/
private static final Set<String> SOURCE_CONNECTION_REQUEST_IDS = new HashSet<>(Arrays.asList(
// 源通讯检测
"yjc_ytxjy"
// 可以根据实际业务需求添加更多requestId
));
/**
* 需要建立被检设备通道的requestId集合
* 这些requestId在发送消息时如果被检设备通道不存在会自动建立连接
*/
private static final Set<String> DEVICE_CONNECTION_REQUEST_IDS = new HashSet<>(Arrays.asList(
// 连接建立
"yjc_sbtxjy",
// ftp文件传送指令
"FTP_SEND$01"
// 可以根据实际业务需求添加更多requestId
));
/**
* 检查指定的requestId是否需要建立程控源连接
*
* @param requestId 请求ID
* @return boolean true:需要建立连接, false:不需要建立连接
*/
public static boolean needsSourceConnection(String requestId) {
return SOURCE_CONNECTION_REQUEST_IDS.contains(requestId);
}
/**
* 检查指定的requestId是否需要建立被检设备连接
*
* @param requestId 请求ID
* @return boolean true:需要建立连接, false:不需要建立连接
*/
public static boolean needsDeviceConnection(String requestId) {
return DEVICE_CONNECTION_REQUEST_IDS.contains(requestId);
}
/**
* 添加需要建立程控源连接的requestId
* 支持运行时动态添加
*
* @param requestId 请求ID
*/
public static void addSourceConnectionRequestId(String requestId) {
SOURCE_CONNECTION_REQUEST_IDS.add(requestId);
}
/**
* 添加需要建立被检设备连接的requestId
* 支持运行时动态添加
*
* @param requestId 请求ID
*/
public static void addDeviceConnectionRequestId(String requestId) {
DEVICE_CONNECTION_REQUEST_IDS.add(requestId);
}
/**
* 移除程控源连接requestId
*
* @param requestId 请求ID
*/
public static void removeSourceConnectionRequestId(String requestId) {
SOURCE_CONNECTION_REQUEST_IDS.remove(requestId);
}
/**
* 移除被检设备连接requestId
*
* @param requestId 请求ID
*/
public static void removeDeviceConnectionRequestId(String requestId) {
DEVICE_CONNECTION_REQUEST_IDS.remove(requestId);
}
/**
* 获取所有需要建立程控源连接的requestId集合只读
*
* @return Set<String> requestId集合
*/
public static Set<String> getSourceConnectionRequestIds() {
return new HashSet<>(SOURCE_CONNECTION_REQUEST_IDS);
}
/**
* 获取所有需要建立被检设备连接的requestId集合只读
*
* @return Set<String> requestId集合
*/
public static Set<String> getDeviceConnectionRequestIds() {
return new HashSet<>(DEVICE_CONNECTION_REQUEST_IDS);
}
}