in dubbo-cluster-extensions/dubbo-cluster-specify-address-dubbo3/src/main/java/org/apache/dubbo/rpc/cluster/specifyaddress/DefaultUserSpecifiedServiceAddressBuilder.java [51:88]
public <T> URL buildAddress(List<Invoker<T>> invokers, Address address, Invocation invocation, URL consumerUrl) {
boolean useFixed = false;
URL template = null;
if (!invokers.isEmpty()) {
template = invokers.iterator().next().getUrl();
if (template instanceof InstanceAddressURL) {
useFixed = true;
} else {
if (template.getUrlAddress() == null) {
PathURLAddress urlAddress = new PathURLAddress(template.getProtocol(), template.getUsername(), template.getPassword(), template.getPath(), address.getIp(), address.getPort());
template = new ServiceConfigURL(urlAddress, template.getUrlParam(), template.getAttributes());
} else {
template = template.setHost(address.getIp());
if (address.getPort() != 0) {
template = template.setPort(address.getPort());
}
}
}
} else {
useFixed = true;
}
if (useFixed) {
String ip = address.getIp();
int port = address.getPort();
String protocol = consumerUrl.getParameter(PROTOCOL_KEY, DUBBO);
if (port == 0) {
port = protocolExtensionLoader.getExtension(protocol).getDefaultPort();
}
template = new DubboServiceAddressURL(
new PathURLAddress(protocol, null, null, consumerUrl.getPath(), ip, port),
consumerUrl.getUrlParam(), consumerUrl, null);
}
return template;
}