com.tencent.trpc.registry.nacos.config.NacosRegistryCenterConfig Maven / Gradle / Ivy
/*
* Tencent is pleased to support the open source community by making tRPC available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* If you have downloaded a copy of the tRPC source code from Tencent,
* please note that tRPC source code is licensed under the Apache 2.0 License,
* A copy of the Apache 2.0 License can be found in the LICENSE file.
*/
package com.tencent.trpc.registry.nacos.config;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import com.tencent.trpc.core.common.config.PluginConfig;
import org.apache.commons.collections4.MapUtils;
/**
* Configuration of Nacos registry center
* Support for plugin extension configuration parameters
*/
public class NacosRegistryCenterConfig {
/**
* Plugin extension configuration parameters
*/
private final Map parameters;
public NacosRegistryCenterConfig(PluginConfig pluginConfig) {
Objects.requireNonNull(pluginConfig, "the pluginConfig can't be null");
if (MapUtils.isEmpty(pluginConfig.getProperties())) {
throw new IllegalArgumentException("the pluginConfig properties can't be empty");
}
parameters = pluginConfig.getProperties();
}
/**
* Get configuration based on assertion
*
* @param NameToSelect assertion
* @return Configuration
*/
public Map getParameters(Predicate nameToSelect) {
Map selectedParameters = new LinkedHashMap<>();
for (Map.Entry entry : getParameters().entrySet()) {
String name = entry.getKey();
if (nameToSelect.test(name)) {
selectedParameters.put(name, String.valueOf(entry.getValue()));
}
}
return Collections.unmodifiableMap(selectedParameters);
}
public Map getParameters() {
return parameters;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy