refactor(nacos-client:config): rmove un use construct of CacheData
This commit is contained in:
parent
ade510f31d
commit
21ff07563d
@ -39,6 +39,11 @@ public interface ConfigService {
|
|||||||
/**
|
/**
|
||||||
* Get config and register Listener
|
* Get config and register Listener
|
||||||
*
|
*
|
||||||
|
* If you want to pull it yourself when the program starts to get the configuration for the first time,
|
||||||
|
* and the registered Listener is used for future configuration updates, you can keep the original
|
||||||
|
* code unchanged, just add the system parameter: enableRemoteSyncConfig = "true" ( But there is network overhead);
|
||||||
|
* therefore we recommend that you use this interface directly
|
||||||
|
*
|
||||||
* @param dataId dataId
|
* @param dataId dataId
|
||||||
* @param group group
|
* @param group group
|
||||||
* @param timeoutMs read timeout
|
* @param timeoutMs read timeout
|
||||||
|
@ -23,7 +23,6 @@ import com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager;
|
|||||||
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
|
import com.alibaba.nacos.client.config.filter.impl.ConfigResponse;
|
||||||
import com.alibaba.nacos.client.config.utils.MD5;
|
import com.alibaba.nacos.client.config.utils.MD5;
|
||||||
import com.alibaba.nacos.client.utils.LogUtils;
|
import com.alibaba.nacos.client.utils.LogUtils;
|
||||||
import com.alibaba.nacos.client.utils.StringUtils;
|
|
||||||
import com.alibaba.nacos.client.utils.TenantUtil;
|
import com.alibaba.nacos.client.utils.TenantUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@ -263,22 +262,6 @@ public class CacheData {
|
|||||||
this.md5 = getMd5String(content);
|
this.md5 = getMd5String(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheData(ConfigFilterChainManager configFilterChainManager, String name, String dataId, String group,
|
|
||||||
String tenant, String content) {
|
|
||||||
if (null == dataId || null == group) {
|
|
||||||
throw new IllegalArgumentException("dataId=" + dataId + ", group=" + group);
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
this.configFilterChainManager = configFilterChainManager;
|
|
||||||
this.dataId = dataId;
|
|
||||||
this.group = group;
|
|
||||||
this.tenant = tenant;
|
|
||||||
listeners = new CopyOnWriteArrayList<ManagerListenerWrap>();
|
|
||||||
this.isInitializing = true;
|
|
||||||
this.content = StringUtils.isEmpty(content) ? loadCacheContentFromDiskLocal(name, dataId, group, tenant) : content;
|
|
||||||
this.md5 = getMd5String(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================
|
// ==================
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -304,7 +287,7 @@ public class CacheData {
|
|||||||
|
|
||||||
class ManagerListenerWrap {
|
class ManagerListenerWrap {
|
||||||
final Listener listener;
|
final Listener listener;
|
||||||
volatile String lastCallMd5 = CacheData.getMd5String(null);
|
String lastCallMd5 = CacheData.getMd5String(null);
|
||||||
|
|
||||||
ManagerListenerWrap(Listener listener) {
|
ManagerListenerWrap(Listener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
@ -188,15 +188,14 @@ public class ClientWorker {
|
|||||||
cache.setInitializing(true);
|
cache.setInitializing(true);
|
||||||
} else {
|
} else {
|
||||||
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
|
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
|
||||||
String content;
|
|
||||||
// fix issue # 1317
|
// fix issue # 1317
|
||||||
if (enableRemoteSyncConfig) {
|
if (enableRemoteSyncConfig) {
|
||||||
try {
|
try {
|
||||||
content = getServerConfig(dataId, group, tenant, 3000L);
|
String content = getServerConfig(dataId, group, tenant, 3000L);
|
||||||
|
cache.setContent(content);
|
||||||
} catch (NacosException ignore) {
|
} catch (NacosException ignore) {
|
||||||
content = null;
|
// If the remote pull fails, the local snapshot should not be overwritten
|
||||||
}
|
}
|
||||||
cache.setContent(content);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user