use of com.baidu.disconf.client.store.processor.model.DisconfValue in project disconf by knightliao.
the class DisconfItemCoreProcessorImpl method updateOneConfItem.
/**
* 更新一个配置
*/
private void updateOneConfItem(String keyName, DisconfCenterItem disconfCenterItem) throws Exception {
if (disconfCenterItem == null) {
throw new Exception("cannot find disconfCenterItem " + keyName);
}
String value = null;
//
if (DisClientConfig.getInstance().ENABLE_DISCONF) {
//
try {
String url = disconfCenterItem.getRemoteServerUrl();
value = fetcherMgr.getValueFromServer(url);
if (value != null) {
LOGGER.debug("value: " + value);
}
} catch (Exception e) {
LOGGER.error("cannot use remote configuration: " + keyName, e);
LOGGER.info("using local variable: " + keyName);
}
LOGGER.debug("download ok.");
}
//
// 注入到仓库中
//
disconfStoreProcessor.inject2Store(keyName, new DisconfValue(value, null));
LOGGER.debug("inject ok.");
//
if (DisClientConfig.getInstance().ENABLE_DISCONF) {
if (watchMgr != null) {
DisConfCommonModel disConfCommonModel = disconfStoreProcessor.getCommonModel(keyName);
watchMgr.watchPath(this, disConfCommonModel, keyName, DisConfigTypeEnum.ITEM, value);
LOGGER.debug("watch ok.");
} else {
LOGGER.warn("cannot monitor {} because watch mgr is null", keyName);
}
}
}
use of com.baidu.disconf.client.store.processor.model.DisconfValue in project disconf by knightliao.
the class DisconfFileCoreProcessorImpl method updateOneConfFile.
/**
* 更新 一個配置文件, 下载、注入到仓库、Watch 三步骤
*/
private void updateOneConfFile(String fileName, DisconfCenterFile disconfCenterFile) throws Exception {
if (disconfCenterFile == null) {
throw new Exception("cannot find disconfCenterFile " + fileName);
}
String filePath = fileName;
Map<String, Object> dataMap = new HashMap<String, Object>();
//
if (DisClientConfig.getInstance().ENABLE_DISCONF) {
//
try {
String url = disconfCenterFile.getRemoteServerUrl();
filePath = fetcherMgr.downloadFileFromServer(url, fileName, disconfCenterFile.getFileDir());
} catch (Exception e) {
//
// 下载失败了, 尝试使用本地的配置
//
LOGGER.error(e.toString(), e);
LOGGER.warn("using local properties in class path: " + fileName);
// change file path
filePath = fileName;
}
LOGGER.debug("download ok.");
}
try {
dataMap = FileTypeProcessorUtils.getKvMap(disconfCenterFile.getSupportFileTypeEnum(), disconfCenterFile.getFilePath());
} catch (Exception e) {
LOGGER.error("cannot get kv data for " + filePath, e);
}
//
// 注入到仓库中
//
disconfStoreProcessor.inject2Store(fileName, new DisconfValue(null, dataMap));
LOGGER.debug("inject ok.");
//
if (DisClientConfig.getInstance().ENABLE_DISCONF) {
//
// Watch
//
DisConfCommonModel disConfCommonModel = disconfStoreProcessor.getCommonModel(fileName);
if (watchMgr != null) {
watchMgr.watchPath(this, disConfCommonModel, fileName, DisConfigTypeEnum.FILE, GsonUtils.toJson(disconfCenterFile.getKV()));
LOGGER.debug("watch ok.");
} else {
LOGGER.warn("cannot monitor {} because watch mgr is null", fileName);
}
}
}
Aggregations