com.linecorp.armeria.client.Endpoint.withIpAddr()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(4.0k)|赞(0)|评价(0)|浏览(168)

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

Endpoint.withIpAddr介绍

[英]Returns a new host endpoint with the specified IP address.
[中]返回具有指定IP地址的新主机终结点。

代码示例

代码示例来源:origin: line/armeria

  1. /**
  2. * Returns a new host endpoint with the specified IP address.
  3. *
  4. * @return the new endpoint with the specified IP address.
  5. * {@code this} if this endpoint has the same IP address.
  6. *
  7. * @throws IllegalStateException if this endpoint is not a host but a group
  8. */
  9. public Endpoint withIpAddr(@Nullable String ipAddr) {
  10. ensureSingle();
  11. if (ipAddr == null) {
  12. return withoutIpAddr();
  13. }
  14. if (NetUtil.isValidIpV4Address(ipAddr)) {
  15. return withIpAddr(ipAddr, StandardProtocolFamily.INET);
  16. }
  17. if (NetUtil.isValidIpV6Address(ipAddr)) {
  18. if (ipAddr.charAt(0) == '[') {
  19. ipAddr = ipAddr.substring(1, ipAddr.length() - 1);
  20. }
  21. return withIpAddr(ipAddr, StandardProtocolFamily.INET6);
  22. }
  23. throw new IllegalArgumentException("ipAddr: " + ipAddr + " (expected: an IP address)");
  24. }

代码示例来源:origin: line/armeria

  1. builder.add(endpoint.withIpAddr(ipAddr));

代码示例来源:origin: line/centraldogma

  1. private static Endpoint toResolvedHostEndpoint(InetSocketAddress addr) {
  2. return Endpoint.of(addr.getHostString(), addr.getPort())
  3. .withIpAddr(addr.getAddress().getHostAddress());
  4. }
  5. }

代码示例来源:origin: com.linecorp.centraldogma/centraldogma-client-armeria-shaded

  1. private static Endpoint toResolvedHostEndpoint(InetSocketAddress addr) {
  2. return Endpoint.of(addr.getHostString(), addr.getPort())
  3. .withIpAddr(addr.getAddress().getHostAddress());
  4. }
  5. }

代码示例来源:origin: line/centraldogma

  1. @Test
  2. public void buildingWithSingleUnresolvedHost() throws Exception {
  3. final long id = AbstractArmeriaCentralDogmaBuilder.nextAnonymousGroupId.get();
  4. final String expectedGroupName = "centraldogma-anonymous-" + id;
  5. final ArmeriaCentralDogmaBuilder b = new ArmeriaCentralDogmaBuilder();
  6. b.healthCheckIntervalMillis(0);
  7. b.host("1.2.3.4.xip.io");
  8. assertThat(b.endpoint()).isEqualTo(Endpoint.ofGroup(expectedGroupName));
  9. // A new group should be registered.
  10. assertThat(AbstractArmeriaCentralDogmaBuilder.nextAnonymousGroupId).hasValue(id + 1);
  11. final EndpointGroup group = EndpointGroupRegistry.get(expectedGroupName);
  12. assertThat(group).isNotNull();
  13. assertThat(group).isInstanceOf(DnsAddressEndpointGroup.class);
  14. assertThat(group.endpoints()).containsExactly(
  15. Endpoint.of("1.2.3.4.xip.io", 36462).withIpAddr("1.2.3.4"));
  16. }

代码示例来源:origin: line/centraldogma

  1. @Test
  2. public void buildingWithProfile() throws Exception {
  3. final String groupName = "centraldogma-profile-xip";
  4. try {
  5. final ArmeriaCentralDogmaBuilder b = new ArmeriaCentralDogmaBuilder();
  6. b.healthCheckIntervalMillis(0);
  7. b.profile("xip");
  8. final Endpoint endpoint = b.endpoint();
  9. assertThat(endpoint.isGroup()).isTrue();
  10. assertThat(endpoint.groupName()).isEqualTo(groupName);
  11. final EndpointGroup group = EndpointGroupRegistry.get(groupName);
  12. assertThat(group).isNotNull();
  13. assertThat(group).isInstanceOf(CompositeEndpointGroup.class);
  14. final CompositeEndpointGroup compositeGroup = (CompositeEndpointGroup) group;
  15. final List<EndpointGroup> childGroups = compositeGroup.groups();
  16. assertThat(childGroups).hasSize(2);
  17. assertThat(childGroups.get(0)).isInstanceOf(DnsAddressEndpointGroup.class);
  18. assertThat(childGroups.get(1)).isInstanceOf(DnsAddressEndpointGroup.class);
  19. await().untilAsserted(() -> {
  20. final List<Endpoint> endpoints = group.endpoints();
  21. assertThat(endpoints).isNotNull();
  22. assertThat(endpoints).containsExactlyInAnyOrder(
  23. Endpoint.of("1.2.3.4.xip.io", 36462).withIpAddr("1.2.3.4"),
  24. Endpoint.of("5.6.7.8.xip.io", 8080).withIpAddr("5.6.7.8"));
  25. });
  26. } finally {
  27. EndpointGroupRegistry.unregister(groupName);
  28. }
  29. }

代码示例来源:origin: line/centraldogma

  1. assertThat(endpoints).isNotNull();
  2. assertThat(endpoints).containsExactlyInAnyOrder(
  3. Endpoint.of("1.2.3.4.xip.io", 1).withIpAddr("1.2.3.4"),
  4. Endpoint.of("5.6.7.8.xip.io", 2).withIpAddr("5.6.7.8"),
  5. Endpoint.of("4.3.2.1", 3),
  6. Endpoint.of("8.7.6.5", 4));

相关文章