use of com.baidu.disconf.client.common.model.DisconfCenterFile in project disconf by knightliao.
the class DisconfStoreFileProcessorImpl method inject2Instance.
/**
*/
@Override
public void inject2Instance(Object object, String fileName) {
DisconfCenterFile disconfCenterFile = getInstance().getConfFileMap().get(fileName);
// 校验是否存在
if (disconfCenterFile == null) {
LOGGER.error("cannot find " + fileName + " in store....");
return;
}
//
if (object != null) {
// 设置object
disconfCenterFile.setObject(object);
}
// 根据类型设置值
//
// 注入实体
//
Map<String, FileItemValue> keMap = disconfCenterFile.getKeyMaps();
for (String fileItem : keMap.keySet()) {
// 根据类型设置值
try {
//
if (object == null) {
if (keMap.get(fileItem).isStatic()) {
LOGGER.debug(fileItem + " is a static field. ");
keMap.get(fileItem).setValue4StaticFileItem(keMap.get(fileItem).getValue());
}
//
// 非静态类
//
} else {
LOGGER.debug(fileItem + " is a non-static field. ");
if (keMap.get(fileItem).getValue() == null) {
// 如果仓库值为空,则实例 直接使用默认值
Object defaultValue = keMap.get(fileItem).getFieldDefaultValue(object);
keMap.get(fileItem).setValue(defaultValue);
} else {
// 如果仓库里的值为非空,则实例使用仓库里的值
keMap.get(fileItem).setValue4FileItem(object, keMap.get(fileItem).getValue());
}
}
} catch (Exception e) {
LOGGER.error("inject2Instance fileName " + fileName + " " + e.toString(), e);
}
}
}
use of com.baidu.disconf.client.common.model.DisconfCenterFile in project disconf by knightliao.
the class StaticScannerFileMgrImpl method getDisconfFiles.
/**
* 获取配置文件数据
*/
private static List<DisconfCenterBaseModel> getDisconfFiles(ScanStaticModel scanModel) {
List<DisconfCenterBaseModel> disconfCenterFiles = new ArrayList<DisconfCenterBaseModel>();
Set<Class<?>> classSet = scanModel.getDisconfFileClassSet();
for (Class<?> disconfFile : classSet) {
Set<Method> methods = scanModel.getDisconfFileItemMap().get(disconfFile);
if (methods == null) {
continue;
}
DisconfCenterFile disconfCenterFile = transformScanFile(disconfFile, methods);
disconfCenterFiles.add(disconfCenterFile);
}
return disconfCenterFiles;
}
use of com.baidu.disconf.client.common.model.DisconfCenterFile in project disconf by knightliao.
the class StaticScannerFileMgrImpl method transformScanFile.
/**
* 转换配置文件
*/
private static DisconfCenterFile transformScanFile(Class<?> disconfFileClass, Set<Method> methods) {
DisconfCenterFile disconfCenterFile = new DisconfCenterFile();
//
// class
disconfCenterFile.setCls(disconfFileClass);
DisconfFile disconfFileAnnotation = disconfFileClass.getAnnotation(DisconfFile.class);
//
// file name
disconfCenterFile.setFileName(disconfFileAnnotation.filename());
// config file target dir path
disconfCenterFile.setTargetDirPath(disconfFileAnnotation.targetDirPath().trim());
// file type
disconfCenterFile.setSupportFileTypeEnum(SupportFileTypeEnum.getByFileName(disconfFileAnnotation.filename()));
//
// disConfCommonModel
DisConfCommonModel disConfCommonModel = makeDisConfCommonModel(disconfFileAnnotation.app(), disconfFileAnnotation.env(), disconfFileAnnotation.version());
disconfCenterFile.setDisConfCommonModel(disConfCommonModel);
// Remote URL
String url = DisconfWebPathMgr.getRemoteUrlParameter(DisClientSysConfig.getInstance().CONF_SERVER_STORE_ACTION, disConfCommonModel.getApp(), disConfCommonModel.getVersion(), disConfCommonModel.getEnv(), disconfCenterFile.getFileName(), DisConfigTypeEnum.FILE);
disconfCenterFile.setRemoteServerUrl(url);
// fields
Field[] expectedFields = disconfFileClass.getDeclaredFields();
//
// KEY & VALUE
//
Map<String, FileItemValue> keyMaps = new HashMap<String, FileItemValue>();
for (Method method : methods) {
// 获取指定的域
Field field = MethodUtils.getFieldFromMethod(method, expectedFields, DisConfigTypeEnum.FILE);
if (field == null) {
continue;
}
//
DisconfFileItem disconfFileItem = method.getAnnotation(DisconfFileItem.class);
String keyName = disconfFileItem.name();
// access
field.setAccessible(true);
// get setter method
Method setterMethod = MethodUtils.getSetterMethodFromField(disconfFileClass, field);
// static 则直接获取其值
if (Modifier.isStatic(field.getModifiers())) {
try {
FileItemValue fileItemValue = new FileItemValue(field.get(null), field, setterMethod);
keyMaps.put(keyName, fileItemValue);
} catch (Exception e) {
LOGGER.error(e.toString());
}
} else {
// 非static则为Null, 这里我们没有必要获取其Bean的值
FileItemValue fileItemValue = new FileItemValue(null, field, setterMethod);
keyMaps.put(keyName, fileItemValue);
}
}
// 设置
disconfCenterFile.setKeyMaps(keyMaps);
return disconfCenterFile;
}
use of com.baidu.disconf.client.common.model.DisconfCenterFile in project disconf by knightliao.
the class DisconfFileCoreProcessorImpl method callUpdatePipeline.
/**
* @param key
*/
private void callUpdatePipeline(String key) {
Object object = disconfStoreProcessor.getConfData(key);
if (object != null) {
DisconfCenterFile disconfCenterFile = (DisconfCenterFile) object;
IDisconfUpdatePipeline iDisconfUpdatePipeline = DisconfCenterStore.getInstance().getiDisconfUpdatePipeline();
if (iDisconfUpdatePipeline != null) {
try {
iDisconfUpdatePipeline.reloadDisconfFile(key, disconfCenterFile.getFilePath());
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
}
}
}
use of com.baidu.disconf.client.common.model.DisconfCenterFile in project disconf by knightliao.
the class DisconfFileCoreProcessorImpl method processOneItem.
@Override
public void processOneItem(String key) {
LOGGER.debug("==============\tstart to process disconf file: " + key + "\t=============================");
DisconfCenterFile disconfCenterFile = (DisconfCenterFile) disconfStoreProcessor.getConfData(key);
try {
updateOneConfFile(key, disconfCenterFile);
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
}
Aggregations