Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Nov 3, 2024
1 parent 6ff20f4 commit c1a82ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
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 @@ -448,8 +448,10 @@ private Map<ProtocolServiceKeyWithAddress, Invoker<T>> toInvokers(
}

// filter all the service available (version wildcard, group wildcard, protocol wildcard)
List<ProtocolServiceKey> matchedProtocolServiceKeys = getMatchedProtocolServiceKeys(instanceAddressURL, true);
List<ProtocolServiceKey> matchedProtocolServiceKeys =
getMatchedProtocolServiceKeys(instanceAddressURL, true);
if (CollectionUtils.isEmpty(matchedProtocolServiceKeys)) {
// if preferred protocol is not specified, use the default main protocol
matchedProtocolServiceKeys = getMatchedProtocolServiceKeys(instanceAddressURL, false);
}

Expand Down Expand Up @@ -512,27 +514,28 @@ private Map<ProtocolServiceKeyWithAddress, Invoker<T>> toInvokers(
return newUrlInvokerMap;
}

private List<ProtocolServiceKey> getMatchedProtocolServiceKeys(InstanceAddressURL instanceAddressURL, boolean needPreferred) {
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, remove all extra protocols
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());
.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) {
Expand Down

0 comments on commit c1a82ed

Please sign in to comment.