use of org.apache.servicecomb.serviceregistry.cache.InstanceCache in project incubator-servicecomb-java-chassis by apache.
the class MicroserviceVersionRule method resetInstanceCache.
private void resetInstanceCache() {
instanceCache = new InstanceCache(appId, microserviceName, versionRule.getVersionRule(), instances);
versionedCache = new VersionedCache().name(versionRule.getVersionRule()).autoCacheVersion().data(instances);
}
use of org.apache.servicecomb.serviceregistry.cache.InstanceCache in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceVersionRule method setInstances.
@Test
public void setInstances() {
MicroserviceVersion v1 = MicroserviceVersionTestUtils.createMicroserviceVersion("1", "0.0.1");
microserviceVersionRule.addMicroserviceVersion(v1);
MicroserviceVersion v2 = MicroserviceVersionTestUtils.createMicroserviceVersion("2", "2.0.0");
microserviceVersionRule.addMicroserviceVersion(v2);
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setServiceId("1");
instance1.setInstanceId("i1");
MicroserviceInstance instance2 = new MicroserviceInstance();
instance2.setServiceId("2");
instance2.setInstanceId("i2");
MicroserviceInstance instance3 = new MicroserviceInstance();
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());
}
use of org.apache.servicecomb.serviceregistry.cache.InstanceCache in project incubator-servicecomb-java-chassis by apache.
the class AbstractEndpointsCache method getLatestEndpoints.
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;
}
Aggregations