[ 
https://issues.apache.org/jira/browse/SCB-613?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16696546#comment-16696546
 ] 

ASF GitHub Bot commented on SCB-613:
------------------------------------

liubao68 closed pull request #892: [SCB-613]delete useless EndpointsCache 
related classs
URL: https://github.com/apache/servicecomb-java-chassis/pull/892
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java 
b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
index dcd877f40..e1e89056f 100644
--- a/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
+++ b/core/src/main/java/org/apache/servicecomb/core/SCBEngine.java
@@ -30,7 +30,6 @@
 import org.apache.servicecomb.core.BootListener.EventType;
 import org.apache.servicecomb.core.definition.MicroserviceMeta;
 import org.apache.servicecomb.core.definition.loader.SchemaListenerManager;
-import org.apache.servicecomb.core.endpoint.AbstractEndpointsCache;
 import org.apache.servicecomb.core.event.InvocationFinishEvent;
 import org.apache.servicecomb.core.event.InvocationStartEvent;
 import org.apache.servicecomb.core.handler.HandlerConfigUtils;
@@ -208,7 +207,6 @@ private void doInit() throws Exception {
     eventBus.register(this);
 
     
consumerProviderManager.setAppManager(RegistryUtils.getServiceRegistry().getAppManager());
-    AbstractEndpointsCache.init(RegistryUtils.getInstanceCacheManager(), 
transportManager);
 
     triggerEvent(EventType.BEFORE_HANDLER);
     HandlerConfigUtils.init();
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/endpoint/AbstractEndpointsCache.java
 
b/core/src/main/java/org/apache/servicecomb/core/endpoint/AbstractEndpointsCache.java
deleted file mode 100644
index 8501013cc..000000000
--- 
a/core/src/main/java/org/apache/servicecomb/core/endpoint/AbstractEndpointsCache.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.core.endpoint;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.serviceregistry.cache.CacheEndpoint;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCache;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
-import org.springframework.util.StringUtils;
-
-/**
- * registry模块不理解core中的概念
- * 所以要将字符串的各种信息转义一下,方便运行时使用
- */
-public abstract class AbstractEndpointsCache<ENDPOINT> {
-  protected static InstanceCacheManager instanceCacheManager;
-
-  protected static TransportManager transportManager;
-
-  protected List<ENDPOINT> endpoints = new ArrayList<>();
-
-  protected String transportName;
-
-  protected InstanceCache instanceCache = null;
-
-  public static void init(InstanceCacheManager instanceCacheManager, 
TransportManager transportManager) {
-    AbstractEndpointsCache.instanceCacheManager = instanceCacheManager;
-    AbstractEndpointsCache.transportManager = transportManager;
-  }
-
-  /*
-   * transportName 可能为"",表示走任意健康的地址即可
-   */
-  public AbstractEndpointsCache(String appId, String microserviceName, String 
microserviceVersionRule,
-      String transportName) {
-    this.transportName = transportName;
-    this.instanceCache = new InstanceCache(appId, microserviceName, 
microserviceVersionRule, null);
-  }
-
-  public List<ENDPOINT> getLatestEndpoints() {
-    InstanceCache newCache = 
instanceCacheManager.getOrCreate(instanceCache.getAppId(),
-        instanceCache.getMicroserviceName(),
-        instanceCache.getMicroserviceVersionRule());
-    if (!instanceCache.cacheChanged(newCache)) {
-      return endpoints;
-    }
-
-    // 走到这里,肯定已经是存在"有效"地址了(可能是个空列表,表示没有存活的实例)
-    // 先创建,成功了,再走下面的更新逻辑
-    List<ENDPOINT> tmpEndpoints = createEndpoints(newCache);
-
-    this.instanceCache = newCache;
-    this.endpoints = tmpEndpoints;
-    return endpoints;
-  }
-
-  protected List<ENDPOINT> createEndpoints(InstanceCache newCache) {
-    Map<String, List<CacheEndpoint>> transportMap = 
getOrCreateTransportMap(newCache);
-
-    return createEndpoints(transportMap);
-  }
-
-  protected List<ENDPOINT> createEndpoints(Map<String, List<CacheEndpoint>> 
transportMap) {
-    List<ENDPOINT> tmpEndpoints = new ArrayList<>();
-    for (Entry<String, List<CacheEndpoint>> entry : transportMap.entrySet()) {
-      Transport transport = transportManager.findTransport(entry.getKey());
-      if (transport == null) {
-        continue;
-      }
-
-      List<CacheEndpoint> endpointList = entry.getValue();
-      if (endpointList == null) {
-        continue;
-      }
-
-      for (CacheEndpoint cacheEndpoint : endpointList) {
-        ENDPOINT endpoint = createEndpoint(transport, cacheEndpoint);
-        tmpEndpoints.add(endpoint);
-      }
-    }
-    return tmpEndpoints;
-  }
-
-  private Map<String, List<CacheEndpoint>> 
getOrCreateTransportMap(InstanceCache newCache) {
-    Map<String, List<CacheEndpoint>> allTransportMap = 
newCache.getOrCreateTransportMap();
-    if (StringUtils.isEmpty(transportName)) {
-      // 未指定transport,将所有transport全取出来
-      return allTransportMap;
-    }
-
-    Map<String, List<CacheEndpoint>> transportMap = new HashMap<>();
-    transportMap.put(transportName, allTransportMap.get(transportName));
-    return transportMap;
-  }
-
-  protected abstract ENDPOINT createEndpoint(Transport transport, 
CacheEndpoint cacheEndpoint);
-}
diff --git 
a/core/src/main/java/org/apache/servicecomb/core/endpoint/EndpointsCache.java 
b/core/src/main/java/org/apache/servicecomb/core/endpoint/EndpointsCache.java
deleted file mode 100644
index 9fe526628..000000000
--- 
a/core/src/main/java/org/apache/servicecomb/core/endpoint/EndpointsCache.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.core.endpoint;
-
-import org.apache.servicecomb.core.Endpoint;
-import org.apache.servicecomb.core.Transport;
-import org.apache.servicecomb.serviceregistry.cache.CacheEndpoint;
-
-public class EndpointsCache extends AbstractEndpointsCache<Endpoint> {
-
-  public EndpointsCache(String appId, String microserviceName, String 
microserviceVersionRule,
-      String transportName) {
-    super(appId, microserviceName, microserviceVersionRule, transportName);
-  }
-
-  @Override
-  protected Endpoint createEndpoint(Transport transport, CacheEndpoint 
cacheEndpoint) {
-    return new Endpoint(transport, cacheEndpoint.getEndpoint(), 
cacheEndpoint.getInstance());
-  }
-}
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java 
b/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java
index ea6371b46..26ad5f863 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestSCBEngine.java
@@ -57,7 +57,6 @@ public void test(@Injectable ProducerProviderManager 
producerProviderManager,
     new Expectations(RegistryUtils.class) {
       {
         RegistryUtils.getServiceRegistry().getAppManager();
-        RegistryUtils.getInstanceCacheManager();
         RegistryUtils.run();
         RegistryUtils.destroy();
       }
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestTransport.java 
b/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
index abfa20252..1ce5eac3e 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestTransport.java
@@ -23,13 +23,7 @@
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.apache.servicecomb.core.endpoint.EndpointsCache;
 import org.apache.servicecomb.core.transport.TransportManager;
-import org.apache.servicecomb.serviceregistry.api.registry.Microservice;
-import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
-import org.apache.servicecomb.serviceregistry.cache.CacheEndpoint;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCache;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.junit.Assert;
 import org.junit.Test;
@@ -83,35 +77,4 @@ public Endpoint getPublishEndpoint() {
     Assert.assertEquals("test", oEndpoint.getTransport().getName());
     Assert.assertEquals("rest://127.0.0.1:8080", oEndpoint.getEndpoint());
   }
-
-  @Test
-  public void testAbstractTransport(@Mocked Microservice microservice,
-      @Injectable InstanceCacheManager instanceCacheManager, @Injectable 
TransportManager transportManager,
-      @Mocked InstanceCache instanceCache, @Injectable MicroserviceInstance 
instance) {
-    EndpointsCache.init(instanceCacheManager, transportManager);
-    EndpointsCache oEndpointsCache = new EndpointsCache("app", "testname", 
"test", "rest");
-
-    List<Endpoint> endpoionts = oEndpointsCache.getLatestEndpoints();
-    Assert.assertEquals(endpoionts.size(), 0);
-
-    Map<String, List<CacheEndpoint>> allTransportMap = new HashMap<>();
-    CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://127.0.0.1:9999", 
instance);
-    List<CacheEndpoint> restEndpoints = new ArrayList<>();
-    restEndpoints.add(cacheEndpoint);
-    allTransportMap.put("rest", restEndpoints);
-
-    new Expectations() {
-      {
-        instanceCacheManager.getOrCreate(anyString, anyString, anyString);
-        result = instanceCache;
-        instanceCache.cacheChanged((InstanceCache) any);
-        result = true;
-        instanceCache.getOrCreateTransportMap();
-        result = allTransportMap;
-      }
-    };
-
-    endpoionts = oEndpointsCache.getLatestEndpoints();
-    Assert.assertEquals(endpoionts.size(), 1);
-  }
 }
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCache.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCache.java
deleted file mode 100644
index 20583e833..000000000
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCache.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.serviceregistry.cache;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.servicecomb.foundation.common.cache.VersionedCache;
-import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
-import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * 缓存指定微服务的所有实例
- * 当实例状态变化时,需要重新创建InstanceCache,由外部控制
- */
-public class InstanceCache {
-  private static final Logger LOGGER = 
LoggerFactory.getLogger(InstanceCache.class);
-
-  // 引入这个原子变量,是为了避免一个服务长期不用,缓存被删除,下次再初始化的初始版本号,有极小概率等于被删除前的版本号的问题
-  // 如果相等,可能会导致其他没感知删除的模块,在更新流程上,遇到问题
-  private static final AtomicInteger VERSION = new AtomicInteger();
-
-  private int cacheVersion;
-
-  private String appId;
-
-  private String microserviceName;
-
-  // 1.0或1.0+或latest等等,只是规则,不一定表示一个确定的版本
-  private String microserviceVersionRule;
-
-  // key为instanceId
-  private Map<String, MicroserviceInstance> instanceMap;
-
-  private VersionedCache versionedCache;
-
-  // 缓存CacheEndpoint
-  private volatile Map<String, List<CacheEndpoint>> transportMap;
-
-  private Object lockObj = new Object();
-
-  /**
-   * 用于初始化场景
-   */
-  public InstanceCache(String appId, String microserviceName, String 
microserviceVersionRule,
-      Map<String, MicroserviceInstance> instanceMap) {
-    cacheVersion = VERSION.getAndIncrement();
-    this.appId = appId;
-    this.microserviceName = microserviceName;
-    this.microserviceVersionRule = microserviceVersionRule;
-    this.instanceMap = instanceMap;
-    this.versionedCache = new VersionedCache()
-        .name(microserviceVersionRule)
-        .autoCacheVersion()
-        .data(instanceMap);
-  }
-
-  public VersionedCache getVersionedCache() {
-    return versionedCache;
-  }
-
-  public boolean cacheChanged(InstanceCache newCache) {
-    return newCache != null
-        && newCache.instanceMap != null
-        && newCache.cacheVersion != cacheVersion;
-  }
-
-  public Map<String, List<CacheEndpoint>> getOrCreateTransportMap() {
-    if (transportMap == null) {
-      synchronized (lockObj) {
-        if (transportMap == null) {
-          transportMap = createTransportMap();
-        }
-      }
-    }
-    return transportMap;
-  }
-
-  protected Map<String, List<CacheEndpoint>> createTransportMap() {
-    Map<String, List<CacheEndpoint>> transportMap = new HashMap<>();
-    for (MicroserviceInstance instance : instanceMap.values()) {
-      // 过滤到不可用实例
-      if (instance.getStatus() != MicroserviceInstanceStatus.UP) {
-        continue;
-      }
-      for (String endpoint : instance.getEndpoints()) {
-        try {
-          URI uri = URI.create(endpoint);
-          String transportName = uri.getScheme();
-
-          List<CacheEndpoint> cacheEndpointList = 
transportMap.computeIfAbsent(transportName, k -> new ArrayList<>());
-          cacheEndpointList.add(new CacheEndpoint(endpoint, instance));
-        } catch (Exception e) {
-          LOGGER.warn("unrecognized address find, ignore " + endpoint);
-        }
-      }
-    }
-    return transportMap;
-  }
-
-  public Map<String, MicroserviceInstance> getInstanceMap() {
-    return instanceMap;
-  }
-
-  public String getMicroserviceName() {
-    return microserviceName;
-  }
-
-  public String getMicroserviceVersionRule() {
-    return microserviceVersionRule;
-  }
-
-  public String getAppId() {
-    return appId;
-  }
-}
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
index 43a737736..9a3a315cd 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManager.java
@@ -20,7 +20,5 @@
 import org.apache.servicecomb.foundation.common.cache.VersionedCache;
 
 public interface InstanceCacheManager {
-  InstanceCache getOrCreate(String appId, String microserviceName, String 
microserviceVersionRule);
-
   VersionedCache getOrCreateVersionedCache(String appId, String 
microserviceName, String microserviceVersionRule);
 }
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManagerNew.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManagerNew.java
index 5b0d839be..5760f40c3 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManagerNew.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/cache/InstanceCacheManagerNew.java
@@ -27,12 +27,6 @@ public InstanceCacheManagerNew(AppManager appManager) {
     this.appManager = appManager;
   }
 
-  @Override
-  public InstanceCache getOrCreate(String appId, String microserviceName, 
String microserviceVersionRule) {
-    return appManager.getOrCreateMicroserviceVersionRule(appId, 
microserviceName, microserviceVersionRule)
-        .getInstanceCache();
-  }
-
   @Override
   public VersionedCache getOrCreateVersionedCache(String appId, String 
microserviceName,
       String microserviceVersionRule) {
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/IpPortManager.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/IpPortManager.java
index 0d5db0a6b..2898faa60 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/IpPortManager.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/IpPortManager.java
@@ -24,14 +24,21 @@
 import java.util.List;
 import java.util.Random;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import org.apache.servicecomb.foundation.common.net.IpPort;
 import org.apache.servicecomb.foundation.common.net.URIEndpointObject;
 import org.apache.servicecomb.serviceregistry.cache.CacheEndpoint;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCache;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
 import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
 import org.apache.servicecomb.serviceregistry.definition.DefinitionConst;
+import org.apache.servicecomb.foundation.common.cache.VersionedCache;
+import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
+import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,6 +53,11 @@
 
   private ArrayList<IpPort> defaultIpPort;
 
+  private Object lockObj = new Object();
+
+   // 缓存CacheEndpoint
+  private volatile Map<String, List<CacheEndpoint>> transportMap;
+
   private AtomicInteger currentAvailableIndex;
 
   private boolean autoDiscoveryInited = false;
@@ -58,7 +70,6 @@ public int getMaxRetryTimes() {
 
   public IpPortManager(ServiceRegistryConfig serviceRegistryConfig, 
InstanceCacheManager instanceCacheManager) {
     this.serviceRegistryConfig = serviceRegistryConfig;
-    this.instanceCacheManager = instanceCacheManager;
 
     defaultTransport = serviceRegistryConfig.getTransport();
     defaultIpPort = serviceRegistryConfig.getIpPort();
@@ -73,7 +84,7 @@ public IpPortManager(ServiceRegistryConfig 
serviceRegistryConfig, InstanceCacheM
   // we have to do this operation after the first time setup has already done
   public void initAutoDiscovery() {
     if (!autoDiscoveryInited && 
this.serviceRegistryConfig.isRegistryAutoDiscovery()) {
-      instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
+      instanceCacheManager.getOrCreateVersionedCache(REGISTRY_APP_ID,
           REGISTRY_SERVICE_NAME,
           DefinitionConst.VERSION_RULE_LATEST);
       autoDiscoveryInited = true;
@@ -100,6 +111,7 @@ private IpPort getAvailableAddress(int index) {
     if (index < defaultIpPort.size()) {
       return defaultIpPort.get(index);
     }
+
     List<CacheEndpoint> endpoints = getDiscoveredIpPort();
     if (endpoints == null || (index >= defaultIpPort.size() + 
endpoints.size())) {
       currentAvailableIndex.set(0);
@@ -114,9 +126,44 @@ private IpPort getAvailableAddress(int index) {
     if (!autoDiscoveryInited || 
!this.serviceRegistryConfig.isRegistryAutoDiscovery()) {
       return null;
     }
-    InstanceCache instanceCache = 
instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
+
+    VersionedCache versionedCache = 
instanceCacheManager.getOrCreateVersionedCache(REGISTRY_APP_ID,
         REGISTRY_SERVICE_NAME,
         DefinitionConst.VERSION_RULE_LATEST);
-    return instanceCache.getOrCreateTransportMap().get(defaultTransport);
+    return getOrCreateTransportMap(versionedCache).get(defaultTransport);
+  }
+
+  public Map<String, List<CacheEndpoint>> 
getOrCreateTransportMap(VersionedCache versionedCache) {
+    if (transportMap == null) {
+      synchronized (lockObj) {
+        if (transportMap == null) {
+          transportMap = createTransportMap(versionedCache);
+        }
+      }
+    }
+    return transportMap;
+  }
+
+  private Map<String, List<CacheEndpoint>> createTransportMap(VersionedCache 
versionedCache) {
+    Map<String, List<CacheEndpoint>> transportMap = new HashMap<>();
+    Map<String, MicroserviceInstance> instances = versionedCache.data();
+
+    for (MicroserviceInstance instance : instances.values()) {
+      // 过滤到不可用实例
+      if (instance.getStatus() != MicroserviceInstanceStatus.UP) {
+        continue;
+      }
+      for (String endpoint : instance.getEndpoints()) {
+        try {
+          URI uri = URI.create(endpoint);
+          String transportName = uri.getScheme();
+           List<CacheEndpoint> cacheEndpointList = 
transportMap.computeIfAbsent(transportName, k -> new ArrayList<>());
+          cacheEndpointList.add(new CacheEndpoint(endpoint, instance));
+        } catch (Exception e) {
+          LOGGER.warn("unrecognized address find, ignore " + endpoint);
+        }
+      }
+    }
+    return transportMap;
   }
 }
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersionRule.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersionRule.java
index cff2fae11..28e210d0b 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersionRule.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersionRule.java
@@ -28,7 +28,6 @@
 
 import org.apache.servicecomb.foundation.common.cache.VersionedCache;
 import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCache;
 import org.apache.servicecomb.serviceregistry.version.VersionRule;
 import org.apache.servicecomb.serviceregistry.version.VersionRuleUtils;
 import org.slf4j.Logger;
@@ -51,8 +50,6 @@
   // key is instanceId
   private Map<String, MicroserviceInstance> instances = Collections.emptyMap();
 
-  private InstanceCache instanceCache;
-
   private VersionedCache versionedCache;
 
   public MicroserviceVersionRule(String appId, String microserviceName, String 
strVersionRule) {
@@ -60,7 +57,7 @@ public MicroserviceVersionRule(String appId, String 
microserviceName, String str
     this.microserviceName = microserviceName;
     this.versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
 
-    resetInstanceCache();
+    resetVersionedCache();
   }
 
   public String getAppId() {
@@ -71,8 +68,7 @@ public String getMicroserviceName() {
     return microserviceName;
   }
 
-  private void resetInstanceCache() {
-    instanceCache = new InstanceCache(appId, microserviceName, 
versionRule.getVersionRule(), instances);
+  private void resetVersionedCache() {
     versionedCache = new VersionedCache()
         .name(versionRule.getVersionRule())
         .autoCacheVersion()
@@ -150,10 +146,6 @@ public VersionRule getVersionRule() {
     return instances;
   }
 
-  public InstanceCache getInstanceCache() {
-    return instanceCache;
-  }
-
   public VersionedCache getVersionedCache() {
     return versionedCache;
   }
@@ -181,7 +173,7 @@ public void setInstances(Collection<MicroserviceInstance> 
newInstances) {
     }).collect(Collectors.toMap(MicroserviceInstance::getInstanceId, 
Function.identity()));
     instances = Collections.unmodifiableMap(tmpInstances);
 
-    resetInstanceCache();
+    resetVersionedCache();
     resetLatestVersion();
   }
 }
diff --git 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
index 033947156..745ee1c1d 100644
--- 
a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
+++ 
b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
@@ -244,7 +244,7 @@ public MicroserviceInstances findServiceInstances(String 
appId, String serviceNa
     if (microserviceInstances.isMicroserviceNotExist()) {
       return microserviceInstances;
     }
-    
+
     if (!microserviceInstances.isNeedRefresh()) {
       LOGGER.debug("instances revision is not changed, service={}/{}/{}", 
appId, serviceName, versionRule);
       return microserviceInstances;
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/cache/TestInstanceCache.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/cache/TestInstanceCache.java
deleted file mode 100644
index cd296080d..000000000
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/cache/TestInstanceCache.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.serviceregistry.cache;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.servicecomb.foundation.common.cache.VersionedCache;
-import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
-import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstanceStatus;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class TestInstanceCache {
-  private static InstanceCache instanceCache = null;
-
-  static Map<String, MicroserviceInstance> instMap = new HashMap<>();
-
-  @BeforeClass
-  public static void beforeClass() {
-    MicroserviceInstance instance = new MicroserviceInstance();
-    instance.setStatus(MicroserviceInstanceStatus.UP);
-    List<String> endpoints = new ArrayList<>();
-    endpoints.add("rest://127.0.0.1:8080");
-    instance.setEndpoints(endpoints);
-    instance.setInstanceId("1");
-
-    instMap.put(instance.getInstanceId(), instance);
-    instanceCache = new InstanceCache("testAppID", "testMicroServiceName", 
"1.0", instMap);
-  }
-
-  @Test
-  public void testGetMethod() {
-    Assert.assertEquals("testAppID", instanceCache.getAppId());
-    Assert.assertEquals("testMicroServiceName", 
instanceCache.getMicroserviceName());
-    Assert.assertEquals("1.0", instanceCache.getMicroserviceVersionRule());
-    Assert.assertNotNull(instanceCache.getInstanceMap());
-  }
-
-  @Test
-  public void testGetOrCreateTransportMap() {
-    Map<String, List<CacheEndpoint>> transportMap = 
instanceCache.getOrCreateTransportMap();
-    Assert.assertEquals(1, transportMap.size());
-  }
-
-  @Test
-  public void testCacheChanged() {
-    InstanceCache newCache =
-        new InstanceCache("testAppID", "testMicroServiceName", "1.0", 
instanceCache.getInstanceMap());
-    Assert.assertTrue(instanceCache.cacheChanged(newCache));
-  }
-
-  @Test
-  public void getVersionedCache() {
-    VersionedCache versionedCache = instanceCache.getVersionedCache();
-    Assert.assertEquals("1.0", versionedCache.name());
-    Assert.assertSame(instMap, versionedCache.data());
-  }
-}
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/cache/TestInstanceCacheManagerNew.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/cache/TestInstanceCacheManagerNew.java
index 54d0589ca..421565d92 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/cache/TestInstanceCacheManagerNew.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/cache/TestInstanceCacheManagerNew.java
@@ -28,25 +28,6 @@
 import mockit.Mocked;
 
 public class TestInstanceCacheManagerNew {
-  @Test
-  public void getOrCreate(@Mocked AppManager appManager, @Mocked 
MicroserviceVersionRule microserviceVersionRule,
-      @Mocked InstanceCache instanceCache) {
-    InstanceCacheManagerNew mgr = new InstanceCacheManagerNew(appManager);
-    String appId = "app";
-    String microserviceName = "ms";
-    String versionRule = DefinitionConst.VERSION_RULE_ALL;
-    new Expectations() {
-      {
-        appManager.getOrCreateMicroserviceVersionRule(appId, microserviceName, 
versionRule);
-        result = microserviceVersionRule;
-        microserviceVersionRule.getInstanceCache();
-        result = instanceCache;
-      }
-    };
-
-    Assert.assertSame(instanceCache, mgr.getOrCreate(appId, microserviceName, 
versionRule));
-  }
-
   @Test
   public void getOrCreateVersionedCache(@Mocked AppManager appManager,
       @Mocked MicroserviceVersionRule microserviceVersionRule,
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
index 771b2d9e7..3602040c9 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/TestIpPortManager.java
@@ -27,11 +27,11 @@
 import org.apache.servicecomb.serviceregistry.RegistryUtils;
 import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
 import org.apache.servicecomb.serviceregistry.cache.CacheEndpoint;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCache;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
 import org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig;
 import org.apache.servicecomb.serviceregistry.registry.AbstractServiceRegistry;
 import org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory;
+import org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager;
+import org.apache.servicecomb.foundation.common.cache.VersionedCache;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -62,8 +62,7 @@ public void setup() {
 
   @Test
   public void testGetAvailableAddress(@Injectable ServiceRegistryConfig config,
-      @Injectable InstanceCacheManager cacheManager,
-      @Injectable InstanceCache cache) {
+               @Injectable InstanceCacheManager cacheManager, @Injectable 
VersionedCache cache) {
     ArrayList<IpPort> ipPortList = new ArrayList<>();
     ipPortList.add(new IpPort("127.0.0.1", 9980));
     ipPortList.add(new IpPort("127.0.0.1", 9981));
@@ -112,11 +111,12 @@ public void testGetAvailableAddress(@Injectable 
ServiceRegistryConfig config,
     List<CacheEndpoint> instances = new ArrayList<>();
     instances.add(new CacheEndpoint("http://127.0.0.1:9982";, null));
     addresses.put("rest", instances);
+
     new Expectations() {
       {
-        cacheManager.getOrCreate("default", "SERVICECENTER", "latest");
+        cacheManager.getOrCreateVersionedCache("default", "SERVICECENTER", 
"latest");
         result = cache;
-        cache.getOrCreateTransportMap();
+        manager.getOrCreateTransportMap(cache);
         result = addresses;
       }
     };
diff --git 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersionRule.java
 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersionRule.java
index 659c8af26..f20cdc52a 100644
--- 
a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersionRule.java
+++ 
b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/consumer/TestMicroserviceVersionRule.java
@@ -20,7 +20,6 @@
 import java.util.Arrays;
 
 import 
org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
-import org.apache.servicecomb.serviceregistry.cache.InstanceCache;
 import org.hamcrest.Matchers;
 import org.junit.Assert;
 import org.junit.Test;
@@ -102,13 +101,9 @@ public void setInstances() {
     instance3.setServiceId("3");
     instance3.setInstanceId("i3");
 
-    InstanceCache orgCache = microserviceVersionRule.getInstanceCache();
     microserviceVersionRule.setInstances(Arrays.asList(instance1, instance2, 
instance3));
 
     Assert.assertThat(microserviceVersionRule.getInstances().values(), 
Matchers.contains(instance2));
-    Assert.assertNotSame(orgCache, microserviceVersionRule.getInstanceCache());
-    Assert.assertSame(microserviceVersionRule.getInstances(),
-        microserviceVersionRule.getInstanceCache().getInstanceMap());
     Assert.assertSame(microserviceVersionRule.getInstances(),
         microserviceVersionRule.getVersionedCache().data());
     
Assert.assertEquals(microserviceVersionRule.getLatestMicroserviceVersion(), v2);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> delete useless EndpointsCache related classs
> --------------------------------------------
>
>                 Key: SCB-613
>                 URL: https://issues.apache.org/jira/browse/SCB-613
>             Project: Apache ServiceComb
>          Issue Type: Task
>          Components: Java-Chassis
>            Reporter: wujimin
>            Assignee: lidian
>            Priority: Major
>              Labels: newbie
>
> all internal logic changed to DiscoveryTree and VersionedCache
> so just delete everything about below classes:
> org.apache.servicecomb.core.endpoint.EndpointsCache
> org.apache.servicecomb.core.endpoint.AbstractEndpointsCache
> org.apache.servicecomb.serviceregistry.cache.InstanceCacheManager#getOrCreate
> org.apache.servicecomb.serviceregistry.cache.InstanceCache



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to