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

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


        for (String fileName : scanModel.getNonAnnotationFileSet()) {

            fileName = fileName.trim();

            DisconfCenterFile disconfCenterFile = new DisconfCenterFile();

            //
            // file name
            disconfCenterFile.setFileName(fileName);

            //
            // disConfCommonModel
            DisConfCommonModel disConfCommonModel = makeDisConfCommonModel("",
                    "");
            disconfCenterFile.setDisConfCommonModel(disConfCommonModel);

            // Remote URL
            String url = DisconfWebPathMgr.getRemoteUrlParameter(
                    DisClientSysConfig.getInstance().CONF_SERVER_STORE_ACTION,
                    disConfCommonModel.getApp(),
                    disConfCommonModel.getVersion(),
                    disConfCommonModel.getEnv(),
                    disconfCenterFile.getFileName(), DisConfigTypeEnum.FILE);
            disconfCenterFile.setRemoteServerUrl(url);

            disconfCenterFiles.add(disconfCenterFile);
        }

        return disconfCenterFiles;
View Full Code Here


    /**
     * 存储 一个配置文件
     */
    public void storeOneFile(DisconfCenterBaseModel disconfCenterBaseModel) {

        DisconfCenterFile disconfCenterFile = (DisconfCenterFile) disconfCenterBaseModel;

        String fileName = disconfCenterFile.getFileName();

        if (confFileMap.containsKey(fileName)) {

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

                    disconfFile);
            if (methods == null) {
                continue;
            }

            DisconfCenterFile disconfCenterFile = transformScanFile(
                    disconfFile, methods);

            disconfCenterFiles.add(disconfCenterFile);
        }
View Full Code Here

     * @return
     */
    private static DisconfCenterFile transformScanFile(
            Class<?> disconfFileClass, Set<Method> methods) {

        DisconfCenterFile disconfCenterFile = new DisconfCenterFile();

        //
        // class
        disconfCenterFile.setCls(disconfFileClass);

        DisconfFile disconfFileAnnotation = disconfFileClass
                .getAnnotation(DisconfFile.class);

        //
        // file name
        disconfCenterFile.setFileName(disconfFileAnnotation.filename());

        //
        // disConfCommonModel
        DisConfCommonModel disConfCommonModel = makeDisConfCommonModel(
                disconfFileAnnotation.env(), disconfFileAnnotation.version());
        disconfCenterFile.setDisConfCommonModel(disConfCommonModel);

        // Remote URL
        String url = DisconfWebPathMgr.getRemoteUrlParameter(
                DisClientSysConfig.getInstance().CONF_SERVER_STORE_ACTION,
                disConfCommonModel.getApp(), disConfCommonModel.getVersion(),
                disConfCommonModel.getEnv(), disconfCenterFile.getFileName(),
                DisConfigTypeEnum.FILE);
        disconfCenterFile.setRemoteServerUrl(url);

        // fields
        Field[] expectedFields = disconfFileClass.getDeclaredFields();

        //
        // KEY & VALUE
        //
        Map<String, FileItemValue> keyMaps = new HashMap<String, FileItemValue>();

        for (Method method : methods) {

            // 获取指定的域
            Field field = MethodUtils.getFieldFromMethod(method,
                    expectedFields, DisConfigTypeEnum.FILE);
            if (field == null) {
                continue;
            }

            //
            DisconfFileItem disconfFileItem = method
                    .getAnnotation(DisconfFileItem.class);
            String keyName = disconfFileItem.name();

            // access
            field.setAccessible(true);

            // static 则直接获取其值
            if (Modifier.isStatic(field.getModifiers())) {
                try {

                    FileItemValue fileItemValue = new FileItemValue(
                            field.get(null), field);
                    keyMaps.put(keyName, fileItemValue);

                } catch (Exception e) {
                    LOGGER.error(e.toString());
                }

            } else {

                // 非static则为Null, 这里我们没有必要获取其Bean的值
                FileItemValue fileItemValue = new FileItemValue(null, field);
                keyMaps.put(keyName, fileItemValue);
            }
        }

        // 设置
        disconfCenterFile.setKeyMaps(keyMaps);

        return disconfCenterFile;
    }
View Full Code Here

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

        DisconfCenterFile disconfCenterFile = DisconfCenterStore.getInstance()
                .getConfFileMap().get(keyName);

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

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

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

        DisconfCenterFile disconfCenterFile = DisconfCenterStore.getInstance()
                .getConfFileMap().get(fileName);

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

        //
        // 静态类
        //
        if (object != null) {
            // 设置object
            disconfCenterFile.setObject(object);
        }

        // 根据类型设置值
        //
        // 注入实体
        //
        Map<String, FileItemValue> keMap = disconfCenterFile.getKeyMaps();
        for (String fileItem : keMap.keySet()) {

            // 根据类型设置值
            try {

View Full Code Here

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

        DisconfCenterFile disconfCenterFile = DisconfCenterStore.getInstance()
                .getConfFileMap().get(fileName);

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

        if (disconfCenterFile.getKeyMaps().get(keyName) == null) {
            LOGGER.debug("canot find " + fileName + ", " + keyName
                    + " in store....");
            return null;
        }

        return disconfCenterFile.getKeyMaps().get(keyName).getValue();
    }
View Full Code Here

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

        DisconfCenterFile disconfCenterFile = DisconfCenterStore.getInstance()
                .getConfFileMap().get(fileName);

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

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

        // 存储
        Map<String, FileItemValue> keMap = disconfCenterFile.getKeyMaps();
        for (String fileItem : keMap.keySet()) {

            Object object = disconfValue.getProperties().get(fileItem);
            if (object == null) {
                LOGGER.error(
                        "cannot find {} to be injectd. file content is: {}",
                        fileItem, disconfValue.getProperties().toString());
                continue;
            }

            // 根据类型设置值
            try {

                Object value = ClassUtils.getValeByType(keMap.get(fileItem)
                        .getField().getType(), object);
                keMap.get(fileItem).setValue(value);

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

            } catch (Exception e) {
                LOGGER.error(
View Full Code Here

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

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

            DisconfCenterFile disconfCenterFile = (DisconfCenterFile) disconfStoreProcessor
                    .getConfData(fileName);

            try {
                updateOneConfFile(fileName, disconfCenterFile);
            } catch (Exception e) {
View Full Code Here

    /**
     * 更新消息:某个配置文件
     */
    private void updateOneConf(String fileName) throws Exception {

        DisconfCenterFile disconfCenterFile = (DisconfCenterFile) disconfStoreProcessor
                .getConfData(fileName);

        if (disconfCenterFile != null) {

            // 更新仓库
View Full Code Here

TOP

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

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.