Search in sources :

Example 1 with DisconfKey

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;
}
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 DisconfKey

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);
    }
}
Also used : DisconfKey(com.baidu.disconf.client.common.model.DisconfKey)

Example 3 with DisconfKey

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());
        }
    }
}
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)

Example 4 with DisconfKey

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);
    }
}
Also used : DisconfFile(com.baidu.disconf.client.common.annotations.DisconfFile) DisconfKey(com.baidu.disconf.client.common.model.DisconfKey)

Aggregations

DisconfKey (com.baidu.disconf.client.common.model.DisconfKey)4 IDisconfUpdate (com.baidu.disconf.client.common.update.IDisconfUpdate)2 DisconfFile (com.baidu.disconf.client.common.annotations.DisconfFile)1 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