com.baidu.disconf.client.common.update.IDisconfUpdate Java Examples

The following examples show how to use com.baidu.disconf.client.common.update.IDisconfUpdate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScanVerify.java    From disconf with Apache License 2.0 6 votes vote down vote up
/**
 * 判断回调函数实现的接口是否正确
 */
public static boolean hasIDisconfUpdate(Class<?> disconfUpdateServiceClass) {

    Class<?>[] interfaceClasses = disconfUpdateServiceClass.getInterfaces();
    boolean hasInterface = false;
    for (Class<?> infClass : interfaceClasses) {
        if (infClass.equals(IDisconfUpdate.class)) {
            hasInterface = true;
        }
    }
    if (!hasInterface) {
        LOGGER.error("Your class " + disconfUpdateServiceClass.toString() + " should implement interface: " +
                         IDisconfUpdate.class.toString());
        return false;
    }

    return true;
}
 
Example #2
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 6 votes vote down vote up
/**
 * 将一个配置回调item写到map里
 */
private static void addOne2InverseMap(DisconfKey disconfKey, Map<DisconfKey, List<IDisconfUpdate>> inverseMap,
                                      IDisconfUpdate iDisconfUpdate) {

    // 忽略的key 应该忽略掉
    if (DisClientConfig.getInstance().getIgnoreDisconfKeySet().contains(disconfKey.getKey())) {
        return;
    }

    List<IDisconfUpdate> serviceList;

    if (inverseMap.containsKey(disconfKey)) {
        inverseMap.get(disconfKey).add(iDisconfUpdate);
    } else {
        serviceList = new ArrayList<IDisconfUpdate>();
        serviceList.add(iDisconfUpdate);
        inverseMap.put(disconfKey, serviceList);
    }
}
 
Example #3
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 6 votes vote down vote up
/**
 * 将一个配置回调item写到map里
 */
private static void addOne2InverseMap(DisconfKey disconfKey, Map<DisconfKey, List<IDisconfUpdate>> inverseMap,
                                      IDisconfUpdate iDisconfUpdate) {

    // 忽略的key 应该忽略掉
    if (DisClientConfig.getInstance().getIgnoreDisconfKeySet().contains(disconfKey.getKey())) {
        return;
    }

    List<IDisconfUpdate> serviceList;

    if (inverseMap.containsKey(disconfKey)) {
        inverseMap.get(disconfKey).add(iDisconfUpdate);
    } else {
        serviceList = new ArrayList<IDisconfUpdate>();
        serviceList.add(iDisconfUpdate);
        inverseMap.put(disconfKey, serviceList);
    }
}
 
Example #4
Source File: ScanVerify.java    From disconf with Apache License 2.0 6 votes vote down vote up
/**
 * 判断回调函数实现的接口是否正确
 */
public static boolean hasIDisconfUpdate(Class<?> disconfUpdateServiceClass) {

    Class<?>[] interfaceClasses = disconfUpdateServiceClass.getInterfaces();
    boolean hasInterface = false;
    for (Class<?> infClass : interfaceClasses) {
        if (infClass.equals(IDisconfUpdate.class)) {
            hasInterface = true;
        }
    }
    if (!hasInterface) {
        LOGGER.error("Your class " + disconfUpdateServiceClass.toString() + " should implement interface: " +
                         IDisconfUpdate.class.toString());
        return false;
    }

    return true;
}
 
Example #5
Source File: DisconfStoreItemProcessorImpl.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
public List<IDisconfUpdate> getUpdateCallbackList(String keyName) {

    if (DisconfCenterStore.getInstance().getConfItemMap().containsKey(keyName)) {

        return DisconfCenterStore.getInstance().getConfItemMap().get(keyName).getDisconfCommonCallbackModel()
                .getDisconfConfUpdates();
    }

    return new ArrayList<IDisconfUpdate>();
}
 
Example #6
Source File: DisconfStoreItemProcessorImpl.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
public void addUpdateCallbackList(String keyName, List<IDisconfUpdate> iDisconfUpdateList) {

    if (DisconfCenterStore.getInstance().getConfItemMap().containsKey(keyName)) {

        DisconfCenterStore.getInstance().getConfItemMap().get(keyName).getDisconfCommonCallbackModel()
                .getDisconfConfUpdates().addAll(iDisconfUpdateList);
    }

}
 
Example #7
Source File: DisconfStoreFileProcessorImpl.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
public List<IDisconfUpdate> getUpdateCallbackList(String keyName) {

    if (getInstance().getConfFileMap().containsKey(keyName)) {

        return getInstance().getConfFileMap().get(keyName).getDisconfCommonCallbackModel().getDisconfConfUpdates();
    }

    return new ArrayList<IDisconfUpdate>();
}
 
Example #8
Source File: DisconfStoreFileProcessorImpl.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
public void addUpdateCallbackList(String keyName, List<IDisconfUpdate> iDisconfUpdateList) {

    if (getInstance().getConfFileMap().containsKey(keyName)) {

        getInstance().getConfFileMap().get(keyName).getDisconfCommonCallbackModel().getDisconfConfUpdates()
                .addAll(iDisconfUpdateList);
    }
}
 
Example #9
Source File: DisconfCoreProcessUtils.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * 调用此配置影响的回调函数
 */
public static void callOneConf(DisconfStoreProcessor disconfStoreProcessor,
                               String key) throws Exception {

    List<IDisconfUpdate> iDisconfUpdates = disconfStoreProcessor.getUpdateCallbackList(key);

    //
    // 获取回调函数列表
    //

    // CALL
    for (IDisconfUpdate iDisconfUpdate : iDisconfUpdates) {

        if (iDisconfUpdate != null) {

            LOGGER.info("start to call " + iDisconfUpdate.getClass());

            // set defined
            try {

                iDisconfUpdate.reload();

            } catch (Exception e) {

                LOGGER.error(e.toString(), e);
            }
        }
    }
}
 
Example #10
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * 获取回调接口的实现
 * <p/>
 * // 回调函数需要实例化出来,这里
 * // 非Spring直接New
 * // Spring要GetBean
 * //
 */
private static IDisconfUpdate getIDisconfUpdateInstance(Class<?> disconfUpdateServiceClass, Registry registry) {

    Object iDisconfUpdate = registry.getFirstByType(disconfUpdateServiceClass, true);
    if (iDisconfUpdate == null) {
        return null;
    }
    return (IDisconfUpdate) iDisconfUpdate;

}
 
Example #11
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * 获取回调对应配置项列表
 */
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);
    }
}
 
Example #12
Source File: DisconfStoreItemProcessorImpl.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
public List<IDisconfUpdate> getUpdateCallbackList(String keyName) {

    if (DisconfCenterStore.getInstance().getConfItemMap().containsKey(keyName)) {

        return DisconfCenterStore.getInstance().getConfItemMap().get(keyName).getDisconfCommonCallbackModel()
                .getDisconfConfUpdates();
    }

    return new ArrayList<IDisconfUpdate>();
}
 
Example #13
Source File: DisconfStoreItemProcessorImpl.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
public void addUpdateCallbackList(String keyName, List<IDisconfUpdate> iDisconfUpdateList) {

    if (DisconfCenterStore.getInstance().getConfItemMap().containsKey(keyName)) {

        DisconfCenterStore.getInstance().getConfItemMap().get(keyName).getDisconfCommonCallbackModel()
                .getDisconfConfUpdates().addAll(iDisconfUpdateList);
    }

}
 
Example #14
Source File: DisconfStoreFileProcessorImpl.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
public List<IDisconfUpdate> getUpdateCallbackList(String keyName) {

    if (getInstance().getConfFileMap().containsKey(keyName)) {

        return getInstance().getConfFileMap().get(keyName).getDisconfCommonCallbackModel().getDisconfConfUpdates();
    }

    return new ArrayList<IDisconfUpdate>();
}
 
Example #15
Source File: DisconfStoreFileProcessorImpl.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Override
public void addUpdateCallbackList(String keyName, List<IDisconfUpdate> iDisconfUpdateList) {

    if (getInstance().getConfFileMap().containsKey(keyName)) {

        getInstance().getConfFileMap().get(keyName).getDisconfCommonCallbackModel().getDisconfConfUpdates()
                .addAll(iDisconfUpdateList);
    }
}
 
Example #16
Source File: DisconfCoreProcessUtils.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * 调用此配置影响的回调函数
 */
public static void callOneConf(DisconfStoreProcessor disconfStoreProcessor,
                               String key) throws Exception {

    List<IDisconfUpdate> iDisconfUpdates = disconfStoreProcessor.getUpdateCallbackList(key);

    //
    // 获取回调函数列表
    //

    // CALL
    for (IDisconfUpdate iDisconfUpdate : iDisconfUpdates) {

        if (iDisconfUpdate != null) {

            LOGGER.info("start to call " + iDisconfUpdate.getClass());

            // set defined
            try {

                iDisconfUpdate.reload();

            } catch (Exception e) {

                LOGGER.error(e.toString(), e);
            }
        }
    }
}
 
Example #17
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * 获取回调对应配置项列表
 */
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);
    }
}
 
Example #18
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * 获取回调接口的实现
 * <p/>
 * // 回调函数需要实例化出来,这里
 * // 非Spring直接New
 * // Spring要GetBean
 * //
 */
private static IDisconfUpdate getIDisconfUpdateInstance(Class<?> disconfUpdateServiceClass, Registry registry) {

    Object iDisconfUpdate = registry.getFirstByType(disconfUpdateServiceClass, true);
    if (iDisconfUpdate == null) {
        return null;
    }
    return (IDisconfUpdate) iDisconfUpdate;

}
 
Example #19
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 4 votes vote down vote up
/**
 * 第二次扫描<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());
        }
    }
}
 
Example #20
Source File: ScanDynamicModel.java    From disconf with Apache License 2.0 4 votes vote down vote up
public Map<DisconfKey, List<IDisconfUpdate>> getDisconfUpdateServiceInverseIndexMap() {
    return disconfUpdateServiceInverseIndexMap;
}
 
Example #21
Source File: ScanDynamicModel.java    From disconf with Apache License 2.0 4 votes vote down vote up
public void setDisconfUpdateServiceInverseIndexMap(Map<DisconfKey,
        List<IDisconfUpdate>>
                                                           disconfUpdateServiceInverseIndexMap) {
    this.disconfUpdateServiceInverseIndexMap = disconfUpdateServiceInverseIndexMap;
}
 
Example #22
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 4 votes vote down vote up
/**
 * 第二次扫描, 获取更新 回调的实例<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);

    //
    // set update pipeline
    //
    if (scanModel.getiDisconfUpdatePipeline() != null) {
        IDisconfUpdatePipeline iDisconfUpdatePipeline = getIDisconfUpdatePipelineInstance(scanModel
                .getiDisconfUpdatePipeline(), registry);
        if (iDisconfUpdatePipeline != null) {
            scanDynamicModel.setDisconfUpdatePipeline(iDisconfUpdatePipeline);
        }
    }

    return scanDynamicModel;
}
 
Example #23
Source File: DisconfCommonCallbackModel.java    From disconf with Apache License 2.0 4 votes vote down vote up
public void setDisconfUpdatesActiveBackups(List<IDisconfUpdate> disconfUpdatesActiveBackups) {
    this.disconfUpdatesActiveBackups = disconfUpdatesActiveBackups;
}
 
Example #24
Source File: DisconfCommonCallbackModel.java    From disconf with Apache License 2.0 4 votes vote down vote up
public List<IDisconfUpdate> getDisconfUpdatesActiveBackups() {
    return disconfUpdatesActiveBackups;
}
 
Example #25
Source File: DisconfCommonCallbackModel.java    From disconf with Apache License 2.0 4 votes vote down vote up
public void setDisconfConfUpdates(List<IDisconfUpdate> disconfConfUpdates) {
    this.disconfConfUpdates = disconfConfUpdates;
}
 
Example #26
Source File: DisconfCommonCallbackModel.java    From disconf with Apache License 2.0 4 votes vote down vote up
public List<IDisconfUpdate> getDisconfConfUpdates() {
    return disconfConfUpdates;
}
 
Example #27
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 4 votes vote down vote up
/**
 * 第二次扫描<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());
        }
    }
}
 
Example #28
Source File: DisconfCommonCallbackModel.java    From disconf with Apache License 2.0 4 votes vote down vote up
public List<IDisconfUpdate> getDisconfConfUpdates() {
    return disconfConfUpdates;
}
 
Example #29
Source File: DisconfCommonCallbackModel.java    From disconf with Apache License 2.0 4 votes vote down vote up
public void setDisconfConfUpdates(List<IDisconfUpdate> disconfConfUpdates) {
    this.disconfConfUpdates = disconfConfUpdates;
}
 
Example #30
Source File: ScanDynamicStoreAdapter.java    From disconf with Apache License 2.0 4 votes vote down vote up
/**
 * 第二次扫描, 获取更新 回调的实例<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);

    //
    // set update pipeline
    //
    if (scanModel.getiDisconfUpdatePipeline() != null) {
        IDisconfUpdatePipeline iDisconfUpdatePipeline = getIDisconfUpdatePipelineInstance(scanModel
                .getiDisconfUpdatePipeline(), registry);
        if (iDisconfUpdatePipeline != null) {
            scanDynamicModel.setDisconfUpdatePipeline(iDisconfUpdatePipeline);
        }
    }

    return scanDynamicModel;
}