com.netflix.discovery.shared.Application.getInstances()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(78)

本文整理了Java中com.netflix.discovery.shared.Application.getInstances()方法的一些代码示例,展示了Application.getInstances()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Application.getInstances()方法的具体详情如下:
包路径:com.netflix.discovery.shared.Application
类名称:Application
方法名:getInstances

Application.getInstances介绍

[英]Gets the list of instances associated with this particular application.

Note that the instances are always returned with random order after shuffling to avoid traffic to the same instances during startup. The shuffling always happens once after every fetch cycle as specified in EurekaClientConfig#getRegistryFetchIntervalSeconds.
[中]获取与此特定应用程序关联的实例列表。
请注意,实例在洗牌后总是以随机顺序返回,以避免在启动期间传输到相同实例。按照EurekaClientConfig#getRegistryFetchIntervalSeconds中的指定,洗牌总是在每个提取周期后发生一次。

代码示例

代码示例来源:origin: Netflix/eureka

public static InstanceInfo takeFirst(Applications applications) {
  for (Application application : applications.getRegisteredApplications()) {
    if (!application.getInstances().isEmpty()) {
      return application.getInstances().get(0);
    }
  }
  return null;
}

代码示例来源:origin: Netflix/eureka

public static int countInstances(Applications applications) {
    int count = 0;
    for(Application application: applications.getRegisteredApplications()) {
      count += application.getInstances().size();
    }
    return count;
  }
}

代码示例来源:origin: Netflix/eureka

@Override
  public void serialize(Application value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    jgen.writeStartObject();
    jgen.writeStringField(ELEM_NAME, value.getName());
    jgen.writeObjectField(ELEM_INSTANCE, value.getInstances());
    jgen.writeEndObject();
  }
}

代码示例来源:origin: Netflix/eureka

public static Map<String, InstanceInfo> selectInstancesMappedById(Application application) {
  Map<String, InstanceInfo> result = new HashMap<>();
  for (InstanceInfo instance : application.getInstances()) {
    result.put(instance.getId(), instance);
  }
  return result;
}

代码示例来源:origin: Netflix/eureka

public static void copyApplication(Application source, Application result) {
  if (source != null) {
    for (InstanceInfo instance : source.getInstances()) {
      result.addInstance(instance);
    }
  }
}

代码示例来源:origin: ctripcorp/apollo

public List<InstanceInfo> getMetaServiceInstances() {
 Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_METASERVICE);
 if (application == null) {
  Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_METASERVICE);
 }
 return application != null ? application.getInstances() : Collections.emptyList();
}

代码示例来源:origin: ctripcorp/apollo

public List<InstanceInfo> getAdminServiceInstances() {
  Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_ADMINSERVICE);
  if (application == null) {
   Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_ADMINSERVICE);
  }
  return application != null ? application.getInstances() : Collections.emptyList();
 }
}

代码示例来源:origin: ctripcorp/apollo

public List<InstanceInfo> getConfigServiceInstances() {
 Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_CONFIGSERVICE);
 if (application == null) {
  Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_CONFIGSERVICE);
 }
 return application != null ? application.getInstances() : Collections.emptyList();
}

代码示例来源:origin: Netflix/eureka

public static InstanceInfo selectInstance(Applications applications, String id) {
  for (Application application : applications.getRegisteredApplications()) {
    for (InstanceInfo instance : application.getInstances()) {
      if (instance.getId().equals(id)) {
        return instance;
      }
    }
  }
  return null;
}

代码示例来源:origin: Netflix/eureka

private static String stringifyAppMap(Map<String, Application> applicationMap) {
  StringBuilder builder = new StringBuilder();
  for (Map.Entry<String, Application> entry : applicationMap.entrySet()) {
    String entryAsString = String.format("{ name : %s , instance count: %d }", entry.getKey(),
        entry.getValue().getInstances().size());
    builder.append(entryAsString);
  }
  return builder.toString();
}

代码示例来源:origin: Netflix/eureka

public static Application copyApplication(Application application) {
  Application copy = new Application(application.getName());
  for (InstanceInfo instance : application.getInstances()) {
    copy.addInstance(instance);
  }
  return copy;
}

代码示例来源:origin: Netflix/eureka

public static void deepCopyApplication(Application source, Application result, Transformer<InstanceInfo> transformer) {
  for (InstanceInfo instance : source.getInstances()) {
    InstanceInfo copy = transformer.apply(instance);
    if (copy == instance) {
      copy = new InstanceInfo(instance);
    }
    result.addInstance(copy);
  }
}

代码示例来源:origin: Netflix/eureka

@Override
  public Boolean call() throws Exception {
    List<Application> applicationList = client.getApplications().getRegisteredApplications();
    return !applicationList.isEmpty() && applicationList.get(0).getInstances().size() == 2;
  }
}, 1, TimeUnit.MINUTES);

代码示例来源:origin: Netflix/eureka

public static void copyApplications(Applications source, Applications result) {
  if (source != null) {
    for (Application app : source.getRegisteredApplications()) {
      result.addApplication(new Application(app.getName(), app.getInstances()));
    }
  }
}

代码示例来源:origin: Netflix/eureka

@Test
public void testGetVipWithRemoteRegionRequest() throws Exception {
  Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications();
  String vipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress();
  when(requestHandler.getVip(vipAddress, REMOTE_REGION)).thenReturn(createResponse(vipApps));
  EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getVip(vipAddress, REMOTE_REGION);
  verifyResponseOkWithEntity(vipApps, httpResponse);
}

代码示例来源:origin: Netflix/eureka

@Test
public void testGetSecureVipWithRemoteRegionRequest() throws Exception {
  Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications();
  String secureVipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getSecureVipAddress();
  when(requestHandler.getSecureVip(secureVipAddress, REMOTE_REGION)).thenReturn(createResponse(vipApps));
  EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getSecureVip(secureVipAddress, REMOTE_REGION);
  verifyResponseOkWithEntity(vipApps, httpResponse);
}

代码示例来源:origin: Netflix/eureka

@Test
public void testGetVipRequest() throws Exception {
  Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications();
  String vipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress();
  when(requestHandler.getVip(vipAddress)).thenReturn(createResponse(vipApps));
  EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getVip(vipAddress);
  verifyResponseOkWithEntity(vipApps, httpResponse);
}

代码示例来源:origin: Netflix/eureka

@Test
public void testGetAppsFromAllRemoteRegions() throws Exception {
  Applications apps = registry.getApplicationsFromAllRemoteRegions();
  List<Application> registeredApplications = apps.getRegisteredApplications();
  Assert.assertEquals("Apps size from remote regions do not match", 1, registeredApplications.size());
  Application app = registeredApplications.iterator().next();
  Assert.assertEquals("Added app did not return from remote registry", REMOTE_REGION_APP_NAME, app.getName());
  Assert.assertEquals("Returned app did not have the instance", 1, app.getInstances().size());
}

代码示例来源:origin: Netflix/eureka

@Before
public void setUp() {
  when(clientConfig.getEurekaServerURLContext()).thenReturn("context");
  when(clientConfig.getRegion()).thenReturn("region");
  applications = InstanceInfoGenerator.newBuilder(5, "eurekaRead", "someOther").build().toApplications();
  vipAddress = applications.getRegisteredApplications("eurekaRead").getInstances().get(0).getVIPAddress();
  when(clientFactory.newClient()).thenReturn(httpClient);
  when(httpClient.getVip(vipAddress)).thenReturn(EurekaHttpResponse.anEurekaHttpResponse(200, applications).build());
  resolver = new EurekaHttpResolver(clientConfig, transportConfig, clientFactory, vipAddress);
}

代码示例来源:origin: Netflix/eureka

@Test
public void testGetAppsFromLocalRegionOnly() throws Exception {
  registerInstanceLocally(createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME));
  Applications apps = registry.getApplicationsFromLocalRegionOnly();
  List<Application> registeredApplications = apps.getRegisteredApplications();
  Assert.assertEquals("Apps size from local region do not match", 1, registeredApplications.size());
  Application app = registeredApplications.iterator().next();
  Assert.assertEquals("Added app did not return from local registry", LOCAL_REGION_APP_NAME, app.getName());
  Assert.assertEquals("Returned app did not have the instance", 1, app.getInstances().size());
}

相关文章