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

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

本文整理了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

/**
 * Returns a new host endpoint with the specified IP address.
 *
 * @return the new endpoint with the specified IP address.
 *         {@code this} if this endpoint has the same IP address.
 *
 * @throws IllegalStateException if this endpoint is not a host but a group
 */
public Endpoint withIpAddr(@Nullable String ipAddr) {
  ensureSingle();
  if (ipAddr == null) {
    return withoutIpAddr();
  }
  if (NetUtil.isValidIpV4Address(ipAddr)) {
    return withIpAddr(ipAddr, StandardProtocolFamily.INET);
  }
  if (NetUtil.isValidIpV6Address(ipAddr)) {
    if (ipAddr.charAt(0) == '[') {
      ipAddr = ipAddr.substring(1, ipAddr.length() - 1);
    }
    return withIpAddr(ipAddr, StandardProtocolFamily.INET6);
  }
  throw new IllegalArgumentException("ipAddr: " + ipAddr + " (expected: an IP address)");
}

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

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

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

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

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

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

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

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

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

@Test
public void buildingWithProfile() throws Exception {
  final String groupName = "centraldogma-profile-xip";
  try {
    final ArmeriaCentralDogmaBuilder b = new ArmeriaCentralDogmaBuilder();
    b.healthCheckIntervalMillis(0);
    b.profile("xip");
    final Endpoint endpoint = b.endpoint();
    assertThat(endpoint.isGroup()).isTrue();
    assertThat(endpoint.groupName()).isEqualTo(groupName);
    final EndpointGroup group = EndpointGroupRegistry.get(groupName);
    assertThat(group).isNotNull();
    assertThat(group).isInstanceOf(CompositeEndpointGroup.class);
    final CompositeEndpointGroup compositeGroup = (CompositeEndpointGroup) group;
    final List<EndpointGroup> childGroups = compositeGroup.groups();
    assertThat(childGroups).hasSize(2);
    assertThat(childGroups.get(0)).isInstanceOf(DnsAddressEndpointGroup.class);
    assertThat(childGroups.get(1)).isInstanceOf(DnsAddressEndpointGroup.class);
    await().untilAsserted(() -> {
      final List<Endpoint> endpoints = group.endpoints();
      assertThat(endpoints).isNotNull();
      assertThat(endpoints).containsExactlyInAnyOrder(
          Endpoint.of("1.2.3.4.xip.io", 36462).withIpAddr("1.2.3.4"),
          Endpoint.of("5.6.7.8.xip.io", 8080).withIpAddr("5.6.7.8"));
    });
  } finally {
    EndpointGroupRegistry.unregister(groupName);
  }
}

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

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

相关文章