pandaapo commented on code in PR #10846:
URL: https://github.com/apache/dubbo/pull/10846#discussion_r1014556564
##########
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java:
##########
@@ -175,10 +178,82 @@ private String getSpecifiedProtocol() {
if (StringUtils.isEmpty(protocol)) {
Map<String, String> params =
getApplicationConfig().getParameters();
if (CollectionUtils.isNotEmptyMap(params)) {
- protocol =
getApplicationConfig().getParameters().get(METADATA_SERVICE_PROTOCOL_KEY);
+ protocol = params.get(METADATA_SERVICE_PROTOCOL_KEY);
}
}
+ return StringUtils.isNotEmpty(protocol) ? protocol :
getRelatedOrDefaultProtocol();
+ }
+
+ /**
+ * Get other configured protocol from environment in priority order. If
get nothing, use default dubbo.
+ *
+ * @return
+ */
+ private String getRelatedOrDefaultProtocol() {
+ String protocol = "";
+ // <dubbo:consumer/>
+ List<ModuleModel> moduleModels = applicationModel.getPubModuleModels();
+ breakPoint:
+ for (ModuleModel moduleModel : moduleModels) {
+ Collection<ConsumerConfig> consumers =
moduleModel.getConfigManager().getConsumers();
+ if (CollectionUtils.isNotEmpty(consumers)) {
+ for (ConsumerConfig config : consumers) {
+ protocol = config.getProtocol();
+ if (StringUtils.isNotEmpty(protocol)) {
+ break breakPoint;
+ }
+ }
+ }
+ }
Review Comment:
Thank you so much for your review! But it seems that the logic below can't
be realized by lambda.
https://github.com/apache/dubbo/blob/33c2d1250194104dae4f446783926ef2429478e1/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/metadata/ConfigurableMetadataServiceExporter.java#L215-L231,
now it is `ProtocolConfig` first `List<ProtocolConfig>` second in one
`ProviderConfig`.
```
Stream<ProviderConfig> providerConfigStream = moduleModels.stream()
.map(ModuleModel::getConfigManager)
.map(ModuleConfigManager::getProviders)
.filter(CollectionUtils::isNotEmpty)
.flatMap(Collection::stream);
protocol = providerConfigStream
.map(ProviderConfig::getProtocol)
.filter((protocolConfig) -> protocolConfig != null)
.map(ProtocolConfig::getName)
.findFirst()
.orElse("");
if (StringUtils.isEmpty(protocol)) {
protocol = providerConfigStream
.map(ProviderConfig::getProtocols)
.filter(CollectionUtils::isNotEmpty)
.flatMap(Collection::stream)
.map(ProtocolConfig::getName)
.filter(StringUtils::isNotEmpty)
.findFirst()
.orElse("");
}
```
After using lambda, it becomes `ProtocolConfig` in all `ProviderConfig`
first, then `List<ProviderConfig>` in all `ProviderConfig`.
Do you have a better way to refactor this logic in lambda? Thank you.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]