This is an automated email from the ASF dual-hosted git repository. liubao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
commit 8a7c8bcbd1556359879b6ed568af1089b911f166 Author: liubao <bi...@qq.com> AuthorDate: Thu May 28 16:41:21 2020 +0800 [SCB-1650]fix review comments --- .../registry/consumer/MicroserviceManager.java | 5 +++-- .../registry/AbstractServiceRegistry.java | 20 +++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java index c4636d9..4fb414e 100644 --- a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java +++ b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/consumer/MicroserviceManager.java @@ -20,6 +20,7 @@ package org.apache.servicecomb.registry.consumer; import java.util.HashMap; import java.util.Map; +import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx; import org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent; import org.apache.servicecomb.registry.api.event.task.SafeModeChangeEvent; import org.slf4j.Logger; @@ -33,7 +34,7 @@ public class MicroserviceManager { private String appId; // key: microserviceName - private Map<String, MicroserviceVersions> versionsByName = new HashMap<>(); + private Map<String, MicroserviceVersions> versionsByName = new ConcurrentHashMapEx<>(); private Object lock = new Object(); @@ -57,8 +58,8 @@ public class MicroserviceManager { microserviceVersions = versionsByName.get(microserviceName); if (microserviceVersions == null) { microserviceVersions = new MicroserviceVersions(appManager, appId, microserviceName); - versionsByName.put(microserviceName, microserviceVersions); microserviceVersions.pullInstances(); + versionsByName.put(microserviceName, microserviceVersions); } } } diff --git a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java index ffc17e7..c6ff17e 100644 --- a/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java +++ b/service-registry/registry-service-center/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java @@ -29,23 +29,26 @@ import java.util.concurrent.ExecutorService; import org.apache.servicecomb.foundation.common.concurrency.SuppressedRunnableWrapper; import org.apache.servicecomb.registry.DiscoveryManager; -import org.apache.servicecomb.serviceregistry.RegistryUtils; -import org.apache.servicecomb.serviceregistry.ServiceRegistry; -import org.apache.servicecomb.serviceregistry.api.Const; +import org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent; +import org.apache.servicecomb.registry.api.event.task.RecoveryEvent; +import org.apache.servicecomb.registry.api.event.task.SafeModeChangeEvent; +import org.apache.servicecomb.registry.api.event.task.ShutdownEvent; import org.apache.servicecomb.registry.api.registry.BasePath; import org.apache.servicecomb.registry.api.registry.Framework; import org.apache.servicecomb.registry.api.registry.FrameworkVersions; import org.apache.servicecomb.registry.api.registry.Microservice; import org.apache.servicecomb.registry.api.registry.MicroserviceFactory; import org.apache.servicecomb.registry.api.registry.MicroserviceInstance; -import org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent; -import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient; import org.apache.servicecomb.registry.api.registry.MicroserviceInstances; -import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig; import org.apache.servicecomb.registry.consumer.MicroserviceManager; import org.apache.servicecomb.registry.consumer.StaticMicroserviceVersions; import org.apache.servicecomb.registry.definition.MicroserviceDefinition; import org.apache.servicecomb.registry.definition.MicroserviceNameParser; +import org.apache.servicecomb.serviceregistry.RegistryUtils; +import org.apache.servicecomb.serviceregistry.ServiceRegistry; +import org.apache.servicecomb.serviceregistry.api.Const; +import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient; +import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig; import org.apache.servicecomb.serviceregistry.registry.cache.MicroserviceCache; import org.apache.servicecomb.serviceregistry.registry.cache.MicroserviceCacheKey; import org.apache.servicecomb.serviceregistry.registry.cache.MicroserviceCacheRefreshedEvent; @@ -53,9 +56,6 @@ import org.apache.servicecomb.serviceregistry.registry.cache.RefreshableServiceR import org.apache.servicecomb.serviceregistry.registry.cache.ServiceRegistryCache; import org.apache.servicecomb.serviceregistry.task.MicroserviceServiceCenterTask; import org.apache.servicecomb.serviceregistry.task.ServiceCenterTask; -import org.apache.servicecomb.registry.api.event.task.RecoveryEvent; -import org.apache.servicecomb.registry.api.event.task.SafeModeChangeEvent; -import org.apache.servicecomb.registry.api.event.task.ShutdownEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -262,8 +262,6 @@ public abstract class AbstractServiceRegistry implements ServiceRegistry { } @Override - // TODO: this is for 3rd party invocation, and a better way can be provided - // TODO: microserviceManager.getVersionsByName() can not be used, will delete this in SCB-1949 public void registerMicroserviceMapping(String microserviceName, String version, List<MicroserviceInstance> instances, Class<?> schemaIntfCls) { MicroserviceNameParser parser = new MicroserviceNameParser(microservice.getAppId(), microserviceName);