CrazyHZM commented on code in PR #10649:
URL: https://github.com/apache/dubbo/pull/10649#discussion_r975971284
##########
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceInstance.java:
##########
@@ -286,20 +288,15 @@ public MetadataInfo getServiceMetadata() {
@Override
public void setServiceMetadata(MetadataInfo serviceMetadata) {
this.serviceMetadata = serviceMetadata;
- this.instanceAddressURL = null;
+ this.instanceAddressURL.clear();
}
@Override
public InstanceAddressURL toURL(String protocol) {
- if(instanceAddressURL == null) {
- instanceAddressURL = new HashMap<>();
- }
- InstanceAddressURL result = instanceAddressURL.getOrDefault(protocol,
null);
- if (result == null) {
- instanceAddressURL.put(protocol, new InstanceAddressURL(this,
serviceMetadata, protocol));
- result = instanceAddressURL.get(protocol);
- }
- return result;
+ return instanceAddressURL.computeIfAbsent(protocol, key -> {
+ final InstanceAddressURL url = new InstanceAddressURL(this,
serviceMetadata, protocol);
+ return url;
+ } );
Review Comment:
replace it with lambda
##########
dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/DefaultServiceInstance.java:
##########
@@ -71,7 +73,7 @@ public class DefaultServiceInstance implements
ServiceInstance {
private transient Map<String, String> extendParams;
private transient List<Endpoint> endpoints;
private transient ApplicationModel applicationModel;
- private transient Map<String, InstanceAddressURL> instanceAddressURL;
+ private transient ConcurrentMap<String, InstanceAddressURL>
instanceAddressURL = new ConcurrentHashMap<>();
Review Comment:
ConcurrentMap changed to Map
--
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]