Search in sources :

Example 1 with IDisconfUpdate

use of com.baidu.disconf.client.common.update.IDisconfUpdate 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;
}
Also used : IDisconfUpdatePipeline(com.baidu.disconf.client.common.update.IDisconfUpdatePipeline) HashMap(java.util.HashMap) DisconfKey(com.baidu.disconf.client.common.model.DisconfKey) IDisconfUpdate(com.baidu.disconf.client.common.update.IDisconfUpdate) ScanDynamicModel(com.baidu.disconf.client.scan.inner.dynamic.model.ScanDynamicModel) ArrayList(java.util.ArrayList) List(java.util.List) DisconfUpdateService(com.baidu.disconf.client.common.annotations.DisconfUpdateService)

Example 2 with IDisconfUpdate

use of com.baidu.disconf.client.common.update.IDisconfUpdate 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());
        }
    }
}
Also used : DisconfKey(com.baidu.disconf.client.common.model.DisconfKey) IDisconfUpdate(com.baidu.disconf.client.common.update.IDisconfUpdate) DisconfStoreProcessor(com.baidu.disconf.client.store.DisconfStoreProcessor)

Aggregations

DisconfKey (com.baidu.disconf.client.common.model.DisconfKey)2 IDisconfUpdate (com.baidu.disconf.client.common.update.IDisconfUpdate)2 DisconfUpdateService (com.baidu.disconf.client.common.annotations.DisconfUpdateService)1 IDisconfUpdatePipeline (com.baidu.disconf.client.common.update.IDisconfUpdatePipeline)1 ScanDynamicModel (com.baidu.disconf.client.scan.inner.dynamic.model.ScanDynamicModel)1 DisconfStoreProcessor (com.baidu.disconf.client.store.DisconfStoreProcessor)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1