use of com.baidu.disconf.client.common.model.DisconfCenterItem in project disconf by knightliao.
the class DisconfStoreItemProcessorImpl method inject2Instance.
/**
*/
@Override
public void inject2Instance(Object object, String key) {
DisconfCenterItem disconfCenterItem = DisconfCenterStore.getInstance().getConfItemMap().get(key);
// 校验是否存在
if (disconfCenterItem == null) {
LOGGER.error("cannot find " + key + " in store....");
return;
}
//
if (object != null) {
disconfCenterItem.setObject(object);
}
//
try {
if (object != null) {
LOGGER.debug(disconfCenterItem.getKey() + " is a non-static field. ");
if (disconfCenterItem.getValue() == null) {
// 如果仓库值为空,则实例 直接使用默认值
Object defaultValue = disconfCenterItem.getFieldDefaultValue(object);
disconfCenterItem.setValue(defaultValue);
} else {
// 如果仓库里的值为非空,则实例使用仓库里的值
disconfCenterItem.setValue4FileItem(object, disconfCenterItem.getValue());
}
} else {
//
if (disconfCenterItem.isStatic()) {
LOGGER.debug(disconfCenterItem.getKey() + " is a static field. ");
disconfCenterItem.setValue4StaticFileItem(disconfCenterItem.getValue());
}
}
} catch (Exception e) {
LOGGER.error("inject2Instance key: " + key + " " + e.toString(), e);
}
}
use of com.baidu.disconf.client.common.model.DisconfCenterItem in project disconf by knightliao.
the class DisconfStoreItemProcessorImpl method inject2Store.
/**
*/
@Override
public void inject2Store(String key, DisconfValue disconfValue) {
DisconfCenterItem disconfCenterItem = DisconfCenterStore.getInstance().getConfItemMap().get(key);
// 校验是否存在
if (disconfCenterItem == null) {
LOGGER.error("cannot find " + key + " in store....");
return;
}
if (disconfValue == null || disconfValue.getValue() == null) {
return;
}
//
try {
Object newValue = disconfCenterItem.getFieldValueByType(disconfValue.getValue());
disconfCenterItem.setValue(newValue);
} catch (Exception e) {
LOGGER.error("key: " + key + " " + e.toString(), e);
}
}
use of com.baidu.disconf.client.common.model.DisconfCenterItem in project disconf by knightliao.
the class DisconfItemCoreProcessorImpl method updateOneConf.
/**
* 更新 一个配置
*/
private void updateOneConf(String keyName) throws Exception {
DisconfCenterItem disconfCenterItem = (DisconfCenterItem) disconfStoreProcessor.getConfData(keyName);
if (disconfCenterItem != null) {
// 更新仓库
updateOneConfItem(keyName, disconfCenterItem);
// 更新实例
inject2OneConf(keyName, disconfCenterItem);
}
}
use of com.baidu.disconf.client.common.model.DisconfCenterItem in project disconf by knightliao.
the class StaticScannerItemMgrImpl method transformScanItem.
/**
* 转换配置项
*/
private static DisconfCenterItem transformScanItem(Method method) {
DisconfCenterItem disconfCenterItem = new DisconfCenterItem();
// class
Class<?> cls = method.getDeclaringClass();
// fields
Field[] expectedFields = cls.getDeclaredFields();
// field
Field field = MethodUtils.getFieldFromMethod(method, expectedFields, DisConfigTypeEnum.ITEM);
if (field == null) {
return null;
}
// 获取标注
DisconfItem disconfItem = method.getAnnotation(DisconfItem.class);
// 去掉空格
String key = disconfItem.key().replace(" ", "");
// get setter method
Method setterMethod = MethodUtils.getSetterMethodFromField(cls, field);
disconfCenterItem.setSetMethod(setterMethod);
// field
disconfCenterItem.setField(field);
// key
disconfCenterItem.setKey(key);
// access
field.setAccessible(true);
// object
disconfCenterItem.setObject(null);
// value
if (Modifier.isStatic(field.getModifiers())) {
try {
disconfCenterItem.setValue(field.get(null));
} catch (Exception e) {
LOGGER.error(e.toString());
disconfCenterItem.setValue(null);
}
} else {
disconfCenterItem.setValue(null);
}
//
// disConfCommonModel
DisConfCommonModel disConfCommonModel = makeDisConfCommonModel(disconfItem.app(), disconfItem.env(), disconfItem.version());
disconfCenterItem.setDisConfCommonModel(disConfCommonModel);
// Disconf-web url
String url = DisconfWebPathMgr.getRemoteUrlParameter(DisClientSysConfig.getInstance().CONF_SERVER_STORE_ACTION, disConfCommonModel.getApp(), disConfCommonModel.getVersion(), disConfCommonModel.getEnv(), key, DisConfigTypeEnum.ITEM);
disconfCenterItem.setRemoteServerUrl(url);
return disconfCenterItem;
}
use of com.baidu.disconf.client.common.model.DisconfCenterItem in project disconf by knightliao.
the class DisconfItemCoreProcessorImpl method callUpdatePipeline.
/**
* @param key
*/
private void callUpdatePipeline(String key) {
Object object = disconfStoreProcessor.getConfData(key);
if (object != null) {
DisconfCenterItem disconfCenterItem = (DisconfCenterItem) object;
IDisconfUpdatePipeline iDisconfUpdatePipeline = DisconfCenterStore.getInstance().getiDisconfUpdatePipeline();
if (iDisconfUpdatePipeline != null) {
try {
iDisconfUpdatePipeline.reloadDisconfItem(key, disconfCenterItem.getValue());
} catch (Exception e) {
LOGGER.error(e.toString(), e);
}
}
}
}
Aggregations