feat(SMB): 重构SMB文件服务支持多服务器配置和连接池优化
重构SmbFileService以支持多服务器配置,引入连接池和会话池管理机制。主要变更包括: 1. 实现基于主机的多服务器认证配置 2. 新增连接池和会话池管理,提高连接复用率 3. 添加定时清理空闲连接和会话的功能 4. 优化异常处理和重试机制 5. 改进日志记录和资源释放 同时更新相关配置文件和应用属性以支持新功能: 1. 修改application.properties支持多服务器SMB配置 2. 增强SmbConfig类以管理多服务器配置 3. 添加任务映射到tasker_mapper.json 4. 新增客户端和服务端任务规则文档
This commit is contained in:
@@ -1,30 +1,64 @@
|
||||
package com.ecep.contract.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.hierynomus.smbj.event.SMBEventBus;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.hierynomus.smbj.SMBClient;
|
||||
import com.hierynomus.smbj.auth.NtlmAuthenticator;
|
||||
|
||||
@Configuration()
|
||||
/**
|
||||
* SMB配置类,支持多服务器配置
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "smb")
|
||||
@Data
|
||||
public class SmbConfig {
|
||||
// 多服务器配置,key为服务器标识
|
||||
private Map<String, ServerConfig> servers = new ConcurrentHashMap<>();
|
||||
private SMBEventBus eventBus = new SMBEventBus();
|
||||
|
||||
@Value("${smb.server.username}")
|
||||
@Getter
|
||||
private String username;
|
||||
|
||||
@Value("${smb.server.password}")
|
||||
@Getter
|
||||
private String password;
|
||||
/**
|
||||
* 获取指定主机的配置
|
||||
* 从servers中查找匹配的主机配置
|
||||
*
|
||||
* @param host 主机名
|
||||
* @return 对应的服务器配置,如果未找到则返回null
|
||||
*/
|
||||
public ServerConfig getServerConfig(String host) {
|
||||
// 遍历servers,查找匹配的主机配置
|
||||
for (Map.Entry<String, ServerConfig> entry : servers.entrySet()) {
|
||||
if (entry.getValue().getHost().equals(host)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
// 如果没有找到匹配的主机配置,返回null
|
||||
return null;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SMBClient smbClient() {
|
||||
var smbConfig = com.hierynomus.smbj.SmbConfig.builder()
|
||||
.withMultiProtocolNegotiate(true).withSigningRequired(true)
|
||||
// .withAuthenticators(new NtlmAuthenticator(username, password))
|
||||
.build();
|
||||
return new SMBClient(smbConfig);
|
||||
return new SMBClient(smbConfig, eventBus);
|
||||
}
|
||||
|
||||
public void subscribe(Object listener) {
|
||||
eventBus.subscribe(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务器配置内部类
|
||||
*/
|
||||
@Data
|
||||
public static class ServerConfig {
|
||||
private String host;
|
||||
private String username;
|
||||
private String password;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user