Skip to content

Commit

Permalink
Add TripleConfig to ProtocolConfig as nest configuration (#14077)
Browse files Browse the repository at this point in the history
* Add TripleConfig to ProtocolConfig as nest configuration

* Fix compile issue

* Use default protocol config

* Format code

* Handle the situation where ProtocolConfig is not set

* Follow the old rules and fix some sonar issues

* Add checkDefault method

* Refresh when uninitialized

* Remove needRefresh

---------

Co-authored-by: earthchen <earthchen1996@gmail.com>
  • Loading branch information
finefuture and EarthChen authored May 23, 2024
1 parent 1f6d441 commit b5bb044
Show file tree
Hide file tree
Showing 15 changed files with 886 additions and 252 deletions.
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;

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

0 comments on commit b5bb044

Please sign in to comment.