Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static boolean isMatch(ProtocolServiceKey rule, ProtocolServiceKey target
}

// 4.match protocol
// 4.1. if rule group is *, match all
// 4.1. if rule protocol is *, match all
if (!CommonConstants.ANY_VALUE.equals(rule.getProtocol())) {
// 4.2. if rule protocol is null, match all
if (StringUtils.isNotEmpty(rule.getProtocol())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import static org.apache.dubbo.common.constants.CommonConstants.ENABLED_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INSTANCE_REGISTER_MODE;
import static org.apache.dubbo.common.constants.CommonConstants.IS_EXTRA;
import static org.apache.dubbo.common.constants.CommonConstants.PREFERRED_PROTOCOL;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.PROTOCOL_FAILED_DESTROY_INVOKER;
Expand Down Expand Up @@ -447,23 +448,12 @@ private Map<ProtocolServiceKeyWithAddress, Invoker<T>> toInvokers(
}

// filter all the service available (version wildcard, group wildcard, protocol wildcard)
int port = instanceAddressURL.getPort();
List<ProtocolServiceKey> matchedProtocolServiceKeys =
instanceAddressURL.getMetadataInfo().getMatchedServiceInfos(consumerProtocolServiceKey).stream()
.filter(serviceInfo -> serviceInfo.getPort() <= 0 || serviceInfo.getPort() == port)
// special filter for extra protocols.
.filter(serviceInfo -> {
if (StringUtils.isNotEmpty(
consumerProtocolServiceKey
.getProtocol())) { // if consumer side protocol is specified, use all
// the protocols we got in hand now directly
return true;
} else { // if consumer side protocol is not specified, remove all extra protocols
return StringUtils.isEmpty(serviceInfo.getParameter(IS_EXTRA));
}
})
.map(MetadataInfo.ServiceInfo::getProtocolServiceKey)
.collect(Collectors.toList());
getMatchedProtocolServiceKeys(instanceAddressURL, true);
if (CollectionUtils.isEmpty(matchedProtocolServiceKeys)) {
// if preferred protocol is not specified, use the default main protocol
matchedProtocolServiceKeys = getMatchedProtocolServiceKeys(instanceAddressURL, false);
}

// see org.apache.dubbo.common.ProtocolServiceKey.isSameWith
// check if needed to override the consumer url
Expand Down Expand Up @@ -524,6 +514,31 @@ private Map<ProtocolServiceKeyWithAddress, Invoker<T>> toInvokers(
return newUrlInvokerMap;
}

private List<ProtocolServiceKey> getMatchedProtocolServiceKeys(
InstanceAddressURL instanceAddressURL, boolean needPreferred) {
int port = instanceAddressURL.getPort();
return instanceAddressURL.getMetadataInfo().getMatchedServiceInfos(consumerProtocolServiceKey).stream()
.filter(serviceInfo -> serviceInfo.getPort() <= 0 || serviceInfo.getPort() == port)
// special filter for extra protocols.
.filter(serviceInfo -> {
if (StringUtils.isNotEmpty(
consumerProtocolServiceKey
.getProtocol())) { // if consumer side protocol is specified, use all
// the protocols we got in hand now directly
return true;
} else {
// if consumer side protocol is not specified, choose the preferred or default main protocol
if (needPreferred) {
return serviceInfo.getProtocol().equals(serviceInfo.getParameter(PREFERRED_PROTOCOL));
} else {
return StringUtils.isEmpty(serviceInfo.getParameter(IS_EXTRA));
}
}
})
.map(MetadataInfo.ServiceInfo::getProtocolServiceKey)
.collect(Collectors.toList());
}

private boolean urlChanged(Invoker<T> invoker, InstanceAddressURL newURL, ProtocolServiceKey protocolServiceKey) {
InstanceAddressURL oldURL = (InstanceAddressURL) invoker.getUrl();

Expand Down