|
|
@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 文件上传Factory
|
|
|
|
* 文件上传Factory
|
|
|
@ -48,16 +49,17 @@ public class OssFactory {
|
|
|
|
// 使用租户标识避免多个租户相同key实例覆盖
|
|
|
|
// 使用租户标识避免多个租户相同key实例覆盖
|
|
|
|
String key = properties.getTenantId() + ":" + configKey;
|
|
|
|
String key = properties.getTenantId() + ":" + configKey;
|
|
|
|
OssClient client = CLIENT_CACHE.get(key);
|
|
|
|
OssClient client = CLIENT_CACHE.get(key);
|
|
|
|
if (client == null) {
|
|
|
|
// 客户端不存在或配置不相同则重新构建
|
|
|
|
CLIENT_CACHE.put(key, new OssClient(configKey, properties));
|
|
|
|
if (client == null || !client.checkPropertiesSame(properties)) {
|
|
|
|
log.info("创建OSS实例 key => {}", configKey);
|
|
|
|
ReentrantLock lock = new ReentrantLock();
|
|
|
|
return CLIENT_CACHE.get(key);
|
|
|
|
lock.lock();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// 配置不相同则重新构建
|
|
|
|
CLIENT_CACHE.put(key, new OssClient(configKey, properties));
|
|
|
|
if (!client.checkPropertiesSame(properties)) {
|
|
|
|
log.info("创建OSS实例 key => {}", configKey);
|
|
|
|
CLIENT_CACHE.put(key, new OssClient(configKey, properties));
|
|
|
|
return CLIENT_CACHE.get(key);
|
|
|
|
log.info("重载OSS实例 key => {}", configKey);
|
|
|
|
} finally {
|
|
|
|
return CLIENT_CACHE.get(key);
|
|
|
|
lock.unlock();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return client;
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
}
|
|
|
|