Skip to content

Commit

Permalink
Polish API
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ committed Nov 3, 2024
1 parent 731ecbb commit fe6540f
Showing 1 changed file with 4 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.common.utils.ArrayUtils;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NetUtils;
Expand All @@ -40,7 +39,6 @@
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.cluster.Cluster;
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.support.ClusterUtils;
import org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareCluster;
import org.apache.dubbo.rpc.model.AsyncMethodInfo;
import org.apache.dubbo.rpc.model.ConsumerModel;
Expand Down Expand Up @@ -85,7 +83,6 @@
import static org.apache.dubbo.common.constants.CommonConstants.POD_NAMESPACE;
import static org.apache.dubbo.common.constants.CommonConstants.PROXY_CLASS_REF;
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SEMICOLON_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SVC;
import static org.apache.dubbo.common.constants.CommonConstants.TRIPLE;
Expand All @@ -104,7 +101,6 @@
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
import static org.apache.dubbo.rpc.Constants.LOCAL_PROTOCOL;
import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_STICKY_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.PEER_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;

/**
Expand Down Expand Up @@ -596,47 +592,22 @@ private boolean checkMeshConfig(Map<String, String> referenceParameters) {
return true;
}

/**
* Parse the directly configured url.
*/
private void parseUrl(Map<String, String> referenceParameters) {
String[] us = SEMICOLON_SPLIT_PATTERN.split(url);
if (ArrayUtils.isNotEmpty(us)) {
for (String u : us) {
URL url = URL.valueOf(u);
if (StringUtils.isEmpty(url.getPath())) {
url = url.setPath(interfaceName);
}
url = url.setScopeModel(getScopeModel());
url = url.setServiceModel(consumerModel);
if (UrlUtils.isRegistry(url)) {
urls.add(url.putAttribute(REFER_KEY, referenceParameters));
} else {
URL peerUrl = getScopeModel()
.getApplicationModel()
.getBeanFactory()
.getBean(ClusterUtils.class)
.mergeUrl(url, referenceParameters);
peerUrl = peerUrl.putAttribute(PEER_KEY, true);
urls.add(peerUrl);
}
}
}
}

/**
* Get URLs from the registry and aggregate them.
*/
private void aggregateUrlFromRegistry(Map<String, String> referenceParameters) {
checkRegistry();
if (StringUtils.isNoneEmpty(url)) {
// user specified URL, could be peer-to-peer address, or register center's address.
// parseUrl(referenceParameters);
URL u = URL.valueOf(url);
if (StringUtils.isEmpty(u.getPath())) {
u = u.setPath(interfaceName);
}
referenceParameters.put(Constants.TARGET_PROTOCOL, u.getProtocol());
referenceParameters.put(Constants.DNS_NAME, u.getHost());
referenceParameters.put(Constants.TARGET_PORT, String.valueOf(u.getPort()));
u.getParameters().forEach(referenceParameters::putIfAbsent);
// Use sticky first to reduce connections
referenceParameters.putIfAbsent(CLUSTER_STICKY_KEY, Boolean.TRUE.toString());
// TODO Triple should support lazy connect
referenceParameters.putIfAbsent(LAZY_CONNECT_KEY, Boolean.TRUE.toString());
Expand Down

0 comments on commit fe6540f

Please sign in to comment.