Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TripleConfig to ProtocolConfig as nest configuration #14077

Merged
merged 13 commits into from
May 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.apache.dubbo.common.serialization.PreferSerializationProvider;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.nested.TripleConfig;
import org.apache.dubbo.config.support.Nested;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.model.ApplicationModel;

Expand Down Expand Up @@ -236,6 +238,9 @@ public class ProtocolConfig extends AbstractConfig {
*/
private String jsonCheckLevel;

@Nested
private TripleConfig triple;
finefuture marked this conversation as resolved.
Show resolved Hide resolved

public ProtocolConfig() {}

public ProtocolConfig(ApplicationModel applicationModel) {
Expand Down Expand Up @@ -277,6 +282,11 @@ protected void checkDefault() {
.getBean(PreferSerializationProvider.class)
.getPreferSerialization();
}

if (triple == null) {
triple = new TripleConfig();
}
triple.checkDefault();
}

@Parameter(excluded = true)
Expand Down Expand Up @@ -621,6 +631,14 @@ public void setExtProtocol(String extProtocol) {
this.extProtocol = extProtocol;
}

public TripleConfig getTriple() {
return triple;
}

public void setTriple(TripleConfig triple) {
this.triple = triple;
}

public void mergeProtocol(ProtocolConfig sourceConfig) {
if (sourceConfig == null) {
return;
Expand Down
118 changes: 0 additions & 118 deletions dubbo-common/src/main/java/org/apache/dubbo/config/TripleConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ static <C extends AbstractConfig> List<C> getDefaultConfigs(Map<String, C> confi
List<C> list = configsMap.values().stream()
.filter(c -> TRUE.equals(AbstractConfigManager.isDefaultConfig(c)))
.collect(Collectors.toList());
if (list.size() > 0) {
if (!list.isEmpty()) {
return list;
}

Expand Down Expand Up @@ -635,10 +635,7 @@ protected <T extends AbstractConfig> void checkDefaultAndValidateConfigs(Class<T
* @return
*/
protected <T extends AbstractConfig> boolean isNeedValidation(T config) {
if (config instanceof MetadataReportConfig) {
return false;
}
return true;
return !(config instanceof MetadataReportConfig);
}

private ConfigValidator getConfigValidator() {
Expand All @@ -656,14 +653,11 @@ private ConfigValidator getConfigValidator() {
* @return
*/
protected <T extends AbstractConfig> boolean isRequired(Class<T> clazz) {
if (clazz == RegistryConfig.class
|| clazz == MetadataReportConfig.class
|| clazz == MonitorConfig.class
|| clazz == MetricsConfig.class
|| clazz == TracingConfig.class) {
return false;
}
return true;
return clazz != RegistryConfig.class
&& clazz != MetadataReportConfig.class
&& clazz != MonitorConfig.class
&& clazz != MetricsConfig.class
&& clazz != TracingConfig.class;
}

private <T extends AbstractConfig> boolean shouldAddDefaultConfig(Class<T> clazz) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ public Optional<ProtocolConfig> getProtocol(String idOrName) {
return getConfig(ProtocolConfig.class, idOrName);
}

public ProtocolConfig getOrAddProtocol(String idOrName) {
Optional<ProtocolConfig> protocol = getProtocol(idOrName);
if (protocol.isPresent()) {
return protocol.get();
}
ProtocolConfig protocolConfig = new ProtocolConfig(idOrName);
addProtocol(protocolConfig);
// addProtocol triggers refresh when other protocols exist in the ConfigManager.
// So refresh is only done when ProtocolConfig is not refreshed.
if (!protocolConfig.isRefreshed()) {
protocolConfig.refresh();
}
return protocolConfig;
}

public List<ProtocolConfig> getDefaultProtocols() {
return getDefaultConfigs(ProtocolConfig.class);
}
Expand Down
Loading
Loading