Search in sources :

Example 1 with DisconfStoreProcessor

use of com.baidu.disconf.client.store.DisconfStoreProcessor in project disconf by knightliao.

the class DisconfAspectJ method decideAccess.

/**
 * 获取配置项数据, 只有开启disconf远程才会进行切面
 *
 * @throws Throwable
 */
@Around("anyPublicMethod() && @annotation(disconfItem)")
public Object decideAccess(ProceedingJoinPoint pjp, DisconfItem disconfItem) throws Throwable {
    if (DisClientConfig.getInstance().ENABLE_DISCONF) {
        // 
        // 请求仓库配置数据
        // 
        DisconfStoreProcessor disconfStoreProcessor = DisconfStoreProcessorFactory.getDisconfStoreItemProcessor();
        Object ret = disconfStoreProcessor.getConfig(null, disconfItem.key());
        if (ret != null) {
            LOGGER.debug("using disconf store value: (" + disconfItem.key() + " , " + ret + ")");
            return ret;
        }
    }
    Object rtnOb;
    try {
        // 返回原值
        rtnOb = pjp.proceed();
    } catch (Throwable t) {
        LOGGER.info(t.getMessage());
        throw t;
    }
    return rtnOb;
}
Also used : DisconfStoreProcessor(com.baidu.disconf.client.store.DisconfStoreProcessor) Around(org.aspectj.lang.annotation.Around)

Example 2 with DisconfStoreProcessor

use of com.baidu.disconf.client.store.DisconfStoreProcessor in project disconf by knightliao.

the class DisconfAspectJ method decideAccess.

/**
 * 获取配置文件数据, 只有开启disconf远程才会进行切面
 *
 * @throws Throwable
 */
@Around("anyPublicMethod() && @annotation(disconfFileItem)")
public Object decideAccess(ProceedingJoinPoint pjp, DisconfFileItem disconfFileItem) throws Throwable {
    if (DisClientConfig.getInstance().ENABLE_DISCONF) {
        MethodSignature ms = (MethodSignature) pjp.getSignature();
        Method method = ms.getMethod();
        // 
        // 文件名
        // 
        Class<?> cls = method.getDeclaringClass();
        DisconfFile disconfFile = cls.getAnnotation(DisconfFile.class);
        // 
        // Field名
        // 
        Field field = MethodUtils.getFieldFromMethod(method, cls.getDeclaredFields(), DisConfigTypeEnum.FILE);
        if (field != null) {
            // 
            // 请求仓库配置数据
            // 
            DisconfStoreProcessor disconfStoreProcessor = DisconfStoreProcessorFactory.getDisconfStoreFileProcessor();
            Object ret = disconfStoreProcessor.getConfig(disconfFile.filename(), disconfFileItem.name());
            if (ret != null) {
                LOGGER.debug("using disconf store value: " + disconfFile.filename() + " (" + disconfFileItem.name() + " , " + ret + ")");
                return ret;
            }
        }
    }
    Object rtnOb;
    try {
        // 返回原值
        rtnOb = pjp.proceed();
    } catch (Throwable t) {
        LOGGER.info(t.getMessage());
        throw t;
    }
    return rtnOb;
}
Also used : Field(java.lang.reflect.Field) MethodSignature(org.aspectj.lang.reflect.MethodSignature) DisconfFile(com.baidu.disconf.client.common.annotations.DisconfFile) Method(java.lang.reflect.Method) DisconfStoreProcessor(com.baidu.disconf.client.store.DisconfStoreProcessor) Around(org.aspectj.lang.annotation.Around)

Example 3 with DisconfStoreProcessor

use of com.baidu.disconf.client.store.DisconfStoreProcessor 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 DisconfStoreProcessor

use of com.baidu.disconf.client.store.DisconfStoreProcessor in project disconf by knightliao.

the class DisconfDataGetterDefaultImpl method getByItem.

@Override
public Object getByItem(String itemName) {
    DisconfStoreProcessor disconfStoreProcessor = DisconfStoreProcessorFactory.getDisconfStoreItemProcessor();
    DisconfCenterItem disconfCenterItem = (DisconfCenterItem) disconfStoreProcessor.getConfData(itemName);
    if (disconfCenterItem == null) {
        return null;
    }
    return disconfCenterItem.getValue();
}
Also used : DisconfCenterItem(com.baidu.disconf.client.common.model.DisconfCenterItem) DisconfStoreProcessor(com.baidu.disconf.client.store.DisconfStoreProcessor)

Example 5 with DisconfStoreProcessor

use of com.baidu.disconf.client.store.DisconfStoreProcessor in project disconf by knightliao.

the class DisconfDataGetterDefaultImpl method getByFile.

@Override
public Map<String, Object> getByFile(String fileName) {
    DisconfStoreProcessor disconfStoreProcessor = DisconfStoreProcessorFactory.getDisconfStoreFileProcessor();
    DisconfCenterFile disconfCenterFile = (DisconfCenterFile) disconfStoreProcessor.getConfData(fileName);
    if (disconfCenterFile == null) {
        return new HashMap<String, Object>();
    }
    return disconfCenterFile.getKV();
}
Also used : HashMap(java.util.HashMap) DisconfCenterFile(com.baidu.disconf.client.common.model.DisconfCenterFile) DisconfStoreProcessor(com.baidu.disconf.client.store.DisconfStoreProcessor)

Aggregations

DisconfStoreProcessor (com.baidu.disconf.client.store.DisconfStoreProcessor)5 Around (org.aspectj.lang.annotation.Around)2 DisconfFile (com.baidu.disconf.client.common.annotations.DisconfFile)1 DisconfCenterFile (com.baidu.disconf.client.common.model.DisconfCenterFile)1 DisconfCenterItem (com.baidu.disconf.client.common.model.DisconfCenterItem)1 DisconfKey (com.baidu.disconf.client.common.model.DisconfKey)1 IDisconfUpdate (com.baidu.disconf.client.common.update.IDisconfUpdate)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1