Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.huawei.flowcontrol.common.util;
import com.huawei.flowcontrol.common.config.ConfigConst;
import com.huawei.flowcontrol.common.config.FlowControlConfig;
import com.huawei.flowcontrol.common.config.KafkaConnectBySslSwitch;
import com.huaweicloud.sermant.core.common.LoggerFactory;
import com.huaweicloud.sermant.core.plugin.config.PluginConfigManager;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;
/**
* 配置信息工具类
*
* @author zhouss
* @since 2022-02-11
*/
public class PluginConfigUtil {
private static final Logger LOGGER = LoggerFactory.getLogger();
private static Properties properties;
private PluginConfigUtil() {
}
static {
// 待后续接入配置中心
setPropertiesFromFlowControlConfig(PluginConfigManager.getPluginConfig(FlowControlConfig.class));
}
/**
* 通过Key获取Value
*
* @param key key值
* @return String 通过key获取value
*/
public static String getValueByKey(String key) {
final Object property = properties.get(key);
if (property == null) {
return "";
}
return String.valueOf(property).trim();
}
/**
* 将配置类的配置设置到properties,减少代码修改
*/
private static void setPropertiesFromFlowControlConfig(FlowControlConfig flowControlConfig) {
properties = new Properties();
setValueForProperties(flowControlConfig);
LOGGER.info("All flow-control config following.");
for (Map.Entry