Search in sources :

Example 11 with DisconfCenterFile

use of com.baidu.disconf.client.common.model.DisconfCenterFile in project disconf by knightliao.

the class DisconfStoreFileProcessorImpl method inject2Store.

/**
     *
     */
@Override
public void inject2Store(String fileName, DisconfValue disconfValue) {
    DisconfCenterFile disconfCenterFile = getInstance().getConfFileMap().get(fileName);
    // 校验是否存在
    if (disconfCenterFile == null) {
        LOGGER.error("cannot find " + fileName + " in store....");
        return;
    }
    if (disconfValue == null || disconfValue.getFileData() == null) {
        LOGGER.error("value is null for {}", fileName);
        return;
    }
    // 存储
    Map<String, FileItemValue> keMap = disconfCenterFile.getKeyMaps();
    if (keMap.size() > 0) {
        for (String fileItem : keMap.keySet()) {
            Object object = disconfValue.getFileData().get(fileItem);
            if (object == null) {
                LOGGER.error("cannot find {} to be injected. file content is: {}", fileItem, disconfValue.getFileData().toString());
                continue;
            }
            // 根据类型设置值
            try {
                Object value = keMap.get(fileItem).getFieldValueByType(object);
                keMap.get(fileItem).setValue(value);
            } catch (Exception e) {
                LOGGER.error("inject2Store filename: " + fileName + " " + e.toString(), e);
            }
        }
    }
    // 使用过 XML式配置
    if (disconfCenterFile.isTaggedWithNonAnnotationFile()) {
        if (disconfCenterFile.getSupportFileTypeEnum().equals(SupportFileTypeEnum.PROPERTIES)) {
            // 如果是采用XML进行配置的,则需要利用spring的reload将数据reload到bean里
            ReloadConfigurationMonitor.reload();
        }
        disconfCenterFile.setAdditionalKeyMaps(disconfValue.getFileData());
    }
}
Also used : FileItemValue(com.baidu.disconf.client.common.model.DisconfCenterFile.FileItemValue) DisconfCenterFile(com.baidu.disconf.client.common.model.DisconfCenterFile)

Aggregations

DisconfCenterFile (com.baidu.disconf.client.common.model.DisconfCenterFile)11 FileItemValue (com.baidu.disconf.client.common.model.DisconfCenterFile.FileItemValue)3 DisConfCommonModel (com.baidu.disconf.client.common.model.DisConfCommonModel)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 DisconfFile (com.baidu.disconf.client.common.annotations.DisconfFile)1 DisconfFileItem (com.baidu.disconf.client.common.annotations.DisconfFileItem)1 DisconfCenterBaseModel (com.baidu.disconf.client.common.model.DisconfCenterBaseModel)1 IDisconfUpdatePipeline (com.baidu.disconf.client.common.update.IDisconfUpdatePipeline)1 DisconfStoreProcessor (com.baidu.disconf.client.store.DisconfStoreProcessor)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1