use of com.baidu.disconf.client.common.model.DisconfKey in project disconf by knightliao.
the class ScanDynamicStoreAdapter method analysis4DisconfUpdate.
/**
* 第二次扫描, 获取更新 回调的实例<br/>
* <p/>
* 分析出更新操作的相关配置文件内容
*/
private static ScanDynamicModel analysis4DisconfUpdate(ScanStaticModel scanModel, Registry registry) {
// 配置项或文件
Map<DisconfKey, List<IDisconfUpdate>> inverseMap = new HashMap<DisconfKey, List<IDisconfUpdate>>();
Set<Class<?>> disconfUpdateServiceSet = scanModel.getDisconfUpdateService();
for (Class<?> disconfUpdateServiceClass : disconfUpdateServiceSet) {
// 回调对应的参数
DisconfUpdateService disconfUpdateService = disconfUpdateServiceClass.getAnnotation(DisconfUpdateService.class);
// 校验是否有继承正确,是否继承IDisconfUpdate
if (!ScanVerify.hasIDisconfUpdate(disconfUpdateServiceClass)) {
continue;
}
//
// 获取回调接口实例
IDisconfUpdate iDisconfUpdate = getIDisconfUpdateInstance(disconfUpdateServiceClass, registry);
if (iDisconfUpdate == null) {
continue;
}
//
// 配置项
processItems(inverseMap, disconfUpdateService, iDisconfUpdate);
//
// 配置文件
processFiles(inverseMap, disconfUpdateService, iDisconfUpdate);
}
// set data
ScanDynamicModel scanDynamicModel = new ScanDynamicModel();
scanDynamicModel.setDisconfUpdateServiceInverseIndexMap(inverseMap);
//
if (scanModel.getiDisconfUpdatePipeline() != null) {
IDisconfUpdatePipeline iDisconfUpdatePipeline = getIDisconfUpdatePipelineInstance(scanModel.getiDisconfUpdatePipeline(), registry);
if (iDisconfUpdatePipeline != null) {
scanDynamicModel.setDisconfUpdatePipeline(iDisconfUpdatePipeline);
}
}
return scanDynamicModel;
}
use of com.baidu.disconf.client.common.model.DisconfKey in project disconf by knightliao.
the class ScanDynamicStoreAdapter method processItems.
/**
* 获取回调对应配置项列表
*/
private static void processItems(Map<DisconfKey, List<IDisconfUpdate>> inverseMap, DisconfUpdateService disconfUpdateService, IDisconfUpdate iDisconfUpdate) {
List<String> itemKeys = Arrays.asList(disconfUpdateService.itemKeys());
// 反索引
for (String key : itemKeys) {
DisconfKey disconfKey = new DisconfKey(DisConfigTypeEnum.ITEM, key);
addOne2InverseMap(disconfKey, inverseMap, iDisconfUpdate);
}
}
use of com.baidu.disconf.client.common.model.DisconfKey in project disconf by knightliao.
the class ScanDynamicStoreAdapter method transformUpdateService.
/**
* 第二次扫描<br/>
* 转换 更新 回调函数,将其写到 仓库中
*/
private static void transformUpdateService(Map<DisconfKey, List<IDisconfUpdate>> disconfUpdateServiceInverseIndexMap) {
DisconfStoreProcessor disconfStoreProcessorFile = DisconfStoreProcessorFactory.getDisconfStoreFileProcessor();
DisconfStoreProcessor disconfStoreProcessorItem = DisconfStoreProcessorFactory.getDisconfStoreItemProcessor();
for (DisconfKey disconfKey : disconfUpdateServiceInverseIndexMap.keySet()) {
try {
if (disconfKey.getDisConfigTypeEnum().equals(DisConfigTypeEnum.FILE)) {
if (!disconfStoreProcessorFile.hasThisConf(disconfKey.getKey())) {
throw new Exception();
}
disconfStoreProcessorFile.addUpdateCallbackList(disconfKey.getKey(), disconfUpdateServiceInverseIndexMap.get(disconfKey));
} else if (disconfKey.getDisConfigTypeEnum().equals(DisConfigTypeEnum.ITEM)) {
if (!disconfStoreProcessorItem.hasThisConf(disconfKey.getKey())) {
throw new Exception();
}
disconfStoreProcessorItem.addUpdateCallbackList(disconfKey.getKey(), disconfUpdateServiceInverseIndexMap.get(disconfKey));
}
} catch (Exception e) {
// 找不到回调对应的配置,这是用户配置 错误了
StringBuffer sb = new StringBuffer();
sb.append("cannot find " + disconfKey + "for: ");
for (IDisconfUpdate serClass : disconfUpdateServiceInverseIndexMap.get(disconfKey)) {
sb.append(serClass.toString() + "\t");
}
LOGGER.error(sb.toString());
}
}
}
use of com.baidu.disconf.client.common.model.DisconfKey in project disconf by knightliao.
the class ScanDynamicStoreAdapter method processFiles.
/**
* 获取回调对应的配置文件列表
*/
private static void processFiles(Map<DisconfKey, List<IDisconfUpdate>> inverseMap, DisconfUpdateService disconfUpdateService, IDisconfUpdate iDisconfUpdate) {
// 反索引
List<Class<?>> classes = Arrays.asList(disconfUpdateService.classes());
for (Class<?> curClass : classes) {
// 获取其注解
DisconfFile disconfFile = curClass.getAnnotation(DisconfFile.class);
if (disconfFile == null) {
LOGGER.error("cannot find DisconfFile annotation for class when set callback: {} ", curClass.toString());
continue;
}
DisconfKey disconfKey = new DisconfKey(DisConfigTypeEnum.FILE, disconfFile.filename());
addOne2InverseMap(disconfKey, inverseMap, iDisconfUpdate);
}
// 反索引
List<String> fileKeyList = Arrays.asList(disconfUpdateService.confFileKeys());
for (String fileKey : fileKeyList) {
DisconfKey disconfKey = new DisconfKey(DisConfigTypeEnum.FILE, fileKey);
addOne2InverseMap(disconfKey, inverseMap, iDisconfUpdate);
}
}
Aggregations