refactor(nacos-client:config): rmove un use construct of CacheData

This commit is contained in:
chuntaojun 2019-06-16 08:24:17 +08:00
parent ade510f31d
commit 21ff07563d
3 changed files with 9 additions and 22 deletions

View File

@ -39,6 +39,11 @@ public interface ConfigService {
/**
* 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 group group
* @param timeoutMs read timeout

View File

@ -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.utils.MD5;
import com.alibaba.nacos.client.utils.LogUtils;
import com.alibaba.nacos.client.utils.StringUtils;
import com.alibaba.nacos.client.utils.TenantUtil;
import org.slf4j.Logger;
@ -263,22 +262,6 @@ public class CacheData {
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;
@ -304,7 +287,7 @@ public class CacheData {
class ManagerListenerWrap {
final Listener listener;
volatile String lastCallMd5 = CacheData.getMd5String(null);
String lastCallMd5 = CacheData.getMd5String(null);
ManagerListenerWrap(Listener listener) {
this.listener = listener;

View File

@ -188,15 +188,14 @@ public class ClientWorker {
cache.setInitializing(true);
} else {
cache = new CacheData(configFilterChainManager, agent.getName(), dataId, group, tenant);
String content;
// fix issue # 1317
if (enableRemoteSyncConfig) {
try {
content = getServerConfig(dataId, group, tenant, 3000L);
String content = getServerConfig(dataId, group, tenant, 3000L);
cache.setContent(content);
} catch (NacosException ignore) {
content = null;
// If the remote pull fails, the local snapshot should not be overwritten
}
cache.setContent(content);
}
}