Package com.baidu.disconf.client.common.model

Examples of com.baidu.disconf.client.common.model.DisconfCenterItem


        List<DisconfCenterBaseModel> disconfCenterItems = new ArrayList<DisconfCenterBaseModel>();

        Set<Method> methods = scanModel.getDisconfItemMethodSet();
        for (Method method : methods) {

            DisconfCenterItem disconfCenterItem = transformScanItem(method);

            if (disconfCenterItem != null) {
                disconfCenterItems.add(disconfCenterItem);
            }
        }
View Full Code Here


     *
     * @return
     */
    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(" ", "");

        // 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.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;
    }
View Full Code Here

        for (String key : disconfStoreProcessor.getConfKeySet()) {

            LOGGER.debug("==============\tstart to process disconf item: "
                    + key + "\t=============================");

            DisconfCenterItem disconfCenterItem = (DisconfCenterItem) disconfStoreProcessor
                    .getConfData(key);
            if (disconfCenterItem != null) {
                try {
                    updateOneConfItem(key, disconfCenterItem);
                } catch (Exception e) {
View Full Code Here

    /**
     * 更新 一个配置
     */
    private void updateOneConf(String keyName) throws Exception {

        DisconfCenterItem disconfCenterItem = (DisconfCenterItem) disconfStoreProcessor
                .getConfData(keyName);
        if (disconfCenterItem != null) {

            // 更新仓库
            updateOneConfItem(keyName, disconfCenterItem);
View Full Code Here

        for (String key : disconfStoreProcessor.getConfKeySet()) {

            LOGGER.debug("==============\tstart to inject value to disconf item instance: "
                    + key + "\t=============================");

            DisconfCenterItem disconfCenterItem = (DisconfCenterItem) disconfStoreProcessor
                    .getConfData(key);

            inject2OneConf(key, disconfCenterItem);
        }
    }
View Full Code Here

    /**
     * 存储 一个配置项
     */
    public void storeOneItem(DisconfCenterBaseModel disconfCenterBaseModel) {

        DisconfCenterItem disconfCenterItem = (DisconfCenterItem) disconfCenterBaseModel;

        String key = disconfCenterItem.getKey();

        if (confItemMap.containsKey(key)) {

            LOGGER.error("There are two same fileName!!!! " + "first: "
                    + confItemMap.get(key).getClass().toString() + ", Second: "
                    + disconfCenterItem.getClass().toString());
        } else {
            confItemMap.put(key, disconfCenterItem);
        }
    }
View Full Code Here

     *
     */
    @Override
    public DisConfCommonModel getCommonModel(String keyName) {

        DisconfCenterItem disconfCenterItem = DisconfCenterStore.getInstance()
                .getConfItemMap().get(keyName);

        // 校验是否存在
        if (disconfCenterItem == null) {
            LOGGER.error("canot find " + keyName + " in store....");
            return null;
        }

        return disconfCenterItem.getDisConfCommonModel();
    }
View Full Code Here

     *
     */
    @Override
    public void inject2Instance(Object object, String key) {

        DisconfCenterItem disconfCenterItem = DisconfCenterStore.getInstance()
                .getConfItemMap().get(key);

        // 校验是否存在
        if (disconfCenterItem == null) {
            LOGGER.error("canot find " + key + " in store....");
            return;
        }

        //
        // 非静态类
        //
        if (object != null) {
            disconfCenterItem.setObject(object);
        }

        // 根据类型设置值
        //
        // 注入实体
        //
        try {

            if (object != null) {

                // 默认值
                Object defaultValue = disconfCenterItem.getField().get(object);

                LOGGER.debug(disconfCenterItem.getKey()
                        + " is a non-static field. ");

                if (disconfCenterItem.getValue() == null) {

                    // 如果仓库里的值为空,则实例直接使用默认值,
                    disconfCenterItem.getField().set(object, defaultValue);

                    // 仓库里也使用此值
                    disconfCenterItem.setValue(defaultValue);

                } else {

                    // 如果仓库里的值为非空,则实例使用仓库里的值
                    disconfCenterItem.getField().set(object,
                            disconfCenterItem.getValue());
                }

            } else {

                //
                // 静态类
                //
                if (Modifier.isStatic(disconfCenterItem.getField()
                        .getModifiers())) {
                    LOGGER.debug(disconfCenterItem.getKey()
                            + " is a static field. ");
                    disconfCenterItem.getField().set(null,
                            disconfCenterItem.getValue());
                }
            }

        } catch (Exception e) {
            LOGGER.error("inject2Instance key: " + key + " " + e.toString(), e);
View Full Code Here

     *
     */
    @Override
    public Object getConfig(String fileName, String keyName) {

        DisconfCenterItem disconfCenterItem = DisconfCenterStore.getInstance()
                .getConfItemMap().get(keyName);

        // 校验是否存在
        if (disconfCenterItem == null) {
            LOGGER.debug("canot find " + keyName + " in store....");
            return null;
        }

        return disconfCenterItem.getValue();
    }
View Full Code Here

     *
     */
    @Override
    public void inject2Store(String key, DisconfValue disconfValue) {

        DisconfCenterItem disconfCenterItem = DisconfCenterStore.getInstance()
                .getConfItemMap().get(key);

        // 校验是否存在
        if (disconfCenterItem == null) {
            LOGGER.error("canot find " + key + " in store....");
            return;
        }

        if (disconfValue == null || disconfValue.getValue() == null) {
            LOGGER.error("value is null for {}", key);
            return;
        }

        // 存储
        Class<?> typeClass = disconfCenterItem.getField().getType();

        // 根据类型设置值
        //
        // 注入仓库
        //
        try {

            Object newValue = ClassUtils.getValeByType(typeClass,
                    disconfValue.getValue());
            disconfCenterItem.setValue(newValue);

            // 如果Object非null,则顺便也注入
            if (disconfCenterItem.getObject() != null) {
                disconfCenterItem.getField().set(disconfCenterItem.getObject(),
                        disconfCenterItem.getValue());
            }

        } catch (Exception e) {
            LOGGER.error("key: " + key + " " + e.toString(), e);
            return;
View Full Code Here

TOP

Related Classes of com.baidu.disconf.client.common.model.DisconfCenterItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.