Search in sources :

Example 1 with InstanceCache

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);
}
Also used : VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) InstanceCache(org.apache.servicecomb.serviceregistry.cache.InstanceCache)

Example 2 with InstanceCache

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());
}
Also used : MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) InstanceCache(org.apache.servicecomb.serviceregistry.cache.InstanceCache) Test(org.junit.Test)

Example 3 with InstanceCache

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;
}
Also used : InstanceCache(org.apache.servicecomb.serviceregistry.cache.InstanceCache)

Aggregations

InstanceCache (org.apache.servicecomb.serviceregistry.cache.InstanceCache)3 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)1 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 Test (org.junit.Test)1