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

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

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

Endpoint.of介绍

[英]Creates a new host Endpoint with unspecified port number.
[中]创建具有未指定端口号的新主机终结点。

代码示例

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

/**
 * Creates a new host {@link Endpoint}.
 *
 * @deprecated Use {@link #of(String, int)} and {@link #withWeight(int)},
 *             e.g. {@code Endpoint.of("foo.com", 80).withWeight(500)}.
 */
@Deprecated
public static Endpoint of(String host, int port, int weight) {
  return of(host, port).withWeight(weight);
}

代码示例来源: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/armeria

switch (tokens.length) {
  case 1: //host
    endpoint = Endpoint.of(segment);
    break;
  case 2: { //host and port
    final int port = Integer.parseInt(tokens[1]);
    if (port == 0) {
      endpoint = Endpoint.of(host);
    } else {
      endpoint = Endpoint.of(host, port);
    final int weight = Integer.parseInt(tokens[2]);
    if (port == 0) {
      endpoint = Endpoint.of(host).withWeight(weight);
    } else {
      endpoint = Endpoint.of(host, port).withWeight(weight);

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

@Override
public void serverStarted(Server server) throws Exception {
  if (endpoint == null) {
    assert server.activePort().isPresent();
    endpoint = Endpoint.of(server.defaultHostname(),
                server.activePort().get()
                   .localAddress().getPort());
  }
  client.start();
  final String key = endpoint.host() + '_' + endpoint.port();
  final byte[] value = nodeValueCodec.encode(endpoint);
  client.create()
     .creatingParentsIfNeeded()
     .withMode(CreateMode.EPHEMERAL)
     .forPath(zNodePath + '/' + key, value);
}

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

@Test
  public void convert() {
    assertThat(NodeValueCodec.DEFAULT
              .decodeAll("foo.com, bar.com:8080, 10.0.2.15:0:500, 192.168.1.2:8443:700"))
        .containsExactlyInAnyOrder(Endpoint.of("foo.com"),
                      Endpoint.of("bar.com", 8080),
                      Endpoint.of("10.0.2.15").withWeight(500),
                      Endpoint.of("192.168.1.2", 8443).withWeight(700));
    assertThatThrownBy(() -> NodeValueCodec.DEFAULT
        .decodeAll("http://foo.com:8001, bar.com:8002"))
        .isInstanceOf(EndpointGroupException.class);
  }
}

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

try {
  final String target = stripTrailingDot(DefaultDnsRecordDecoder.decodeName(content));
  endpoint = port > 0 ? Endpoint.of(target, port) : Endpoint.of(target);
} catch (Exception e) {
  content.resetReaderIndex();

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

@Test
public void urlAnnotation_uriWithoutScheme() throws Exception {
  EndpointGroupRegistry.register("bar",
                  new StaticEndpointGroup(Endpoint.of("127.0.0.1", server.httpPort())),
                  ROUND_ROBIN);
  assertThat(service.fullUrl("//localhost:" + server.httpPort() + "/nest/pojo").get()).isEqualTo(
      new Pojo("Leonard", 21));
  assertThat(service.fullUrl("//group_bar/nest/pojo").get()).isEqualTo(new Pojo("Leonard", 21));
  assertThat(service.fullUrl("//localhost:" + server.httpPort() + "/pojo").get()).isEqualTo(
      new Pojo("Cony", 26));
  assertThat(service.fullUrl("//group_bar/pojo").get()).isEqualTo(new Pojo("Cony", 26));
}

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

@Test
public void testUpdateEndpointGroup() throws Throwable {
  Set<Endpoint> expected = ImmutableSet.of(Endpoint.of("127.0.0.1", 8001).withWeight(2),
                       Endpoint.of("127.0.0.1", 8002).withWeight(3));
  // Add two more nodes.
  setNodeChild(expected);
  // Construct the final expected node list.
  final Builder<Endpoint> builder = ImmutableSet.builder();
  builder.addAll(sampleEndpoints).addAll(expected);
  expected = builder.build();
  try (CloseableZooKeeper zk = connection()) {
    zk.sync(zNode, (rc, path, ctx) -> {}, null);
  }
  final Set<Endpoint> finalExpected = expected;
  await().untilAsserted(() -> assertThat(endpointGroup.endpoints()).hasSameElementsAs(finalExpected));
}

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

final Endpoint endpoint = port != 0 ? Endpoint.of(hostname, port) : Endpoint.of(hostname);
builder.add(endpoint.withIpAddr(ipAddr));

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

@Test
public void urlAnnotation() throws Exception {
  EndpointGroupRegistry.register("bar",
                  new StaticEndpointGroup(Endpoint.of("127.0.0.1", server.httpPort())),
                  ROUND_ROBIN);
  final Service service = new ArmeriaRetrofitBuilder()
      .baseUrl("http://group:foo/")
      .addConverterFactory(JacksonConverterFactory.create(OBJECT_MAPPER))
      .build()
      .create(Service.class);
  final Pojo pojo = service.fullUrl("http://group_bar/pojo").get();
  assertThat(pojo).isEqualTo(new Pojo("Cony", 26));
}

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

private static ClientRequestContext newClientContext(
    String path, @Nullable String query) throws Exception {
  final InetSocketAddress remoteAddress = new InetSocketAddress(
      InetAddress.getByAddress("server.com", new byte[] { 1, 2, 3, 4 }), 8080);
  final InetSocketAddress localAddress = new InetSocketAddress(
      InetAddress.getByAddress("client.com", new byte[] { 5, 6, 7, 8 }), 5678);
  final String pathAndQuery = path + (query != null ? '?' + query : "");
  final HttpRequest req = HttpRequest.of(HttpHeaders.of(HttpMethod.GET, pathAndQuery)
                           .authority("server.com:8080")
                           .set(HttpHeaderNames.USER_AGENT, "some-client"));
  final ClientRequestContext ctx =
      ClientRequestContextBuilder.of(req)
                    .remoteAddress(remoteAddress)
                    .localAddress(localAddress)
                    .endpoint(Endpoint.of("server.com", 8080))
                    .sslSession(newSslSession())
                    .build();
  ctx.attr(MY_ATTR).set(new CustomValue("some-attr"));
  return ctx;
}

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

@Test
public void respectsHttpClientUri_endpointGroup() throws Exception {
  EndpointGroupRegistry.register("foo",
                  new StaticEndpointGroup(Endpoint.of("127.0.0.1", server.httpPort())),
                  ROUND_ROBIN);
  final Service service = new ArmeriaRetrofitBuilder()
      .baseUrl("http://group:foo/")
      .addConverterFactory(JacksonConverterFactory.create(OBJECT_MAPPER))
      .build()
      .create(Service.class);
  final Response<Pojo> response = service.postForm("Cony", 26).get();
  // TODO(ide) Use the actual `host:port`. See https://github.com/line/armeria/issues/379
  assertThat(response.raw().request().url()).isEqualTo(
      new HttpUrl.Builder().scheme("http")
                 .host("group_foo")
                 .addPathSegment("postForm")
                 .build());
}

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

Endpoint.of("127.0.0.1", serverOne.httpPort()).withWeight(1),
    Endpoint.of("127.0.0.1", serverTwo.httpPort()).withWeight(2),
    Endpoint.of("127.0.0.1", serverThree.httpPort()).withWeight(3));
final String groupName = name.getMethodName();
final String endpointGroupMark = "group:";
    Endpoint.of("127.0.0.1", serverOne.httpPort()).withWeight(2),
    Endpoint.of("127.0.0.1", serverTwo.httpPort()).withWeight(4),
    Endpoint.of("127.0.0.1", serverThree.httpPort()).withWeight(3));

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

final ClientRequestContext ctx =
    ClientRequestContextBuilder.of(req)
                  .endpoint(Endpoint.of("localhost", 8080))
                  .build();

代码示例来源: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 buildingWithSingleResolvedHost() throws Exception {
  final long id = AbstractArmeriaCentralDogmaBuilder.nextAnonymousGroupId.get();
  final ArmeriaCentralDogmaBuilder b = new ArmeriaCentralDogmaBuilder();
  b.host("1.2.3.4");
  assertThat(b.endpoint()).isEqualTo(Endpoint.of("1.2.3.4", 36462));
  // No new group should be registered.
  assertThat(AbstractArmeriaCentralDogmaBuilder.nextAnonymousGroupId).hasValue(id);
  assertThat(EndpointGroupRegistry.get("centraldogma-anonymous-" + id)).isNull();
}

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

private static ClientRequestContext newClientContext(RpcRequest req) {
    return spy(new DefaultClientRequestContext(
        new DefaultEventLoop(), NoopMeterRegistry.get(), SessionProtocol.HTTP,
        Endpoint.of("localhost", 8080), HttpMethod.POST, "/cd/thrift/v1",
        null, null, ClientOptions.DEFAULT, req));
  }
}

代码示例来源: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

@Test(timeout = 10000)
  public void text() throws Exception {
    try (Watcher<String> watcher = dogma.client().fileWatcher("directory", "my-service",
                                 Query.ofText("/endpoints.txt"))) {
      final CountDownLatch latch = new CountDownLatch(2);
      watcher.watch(unused -> latch.countDown());
      final CentralDogmaEndpointGroup<String> endpointGroup = CentralDogmaEndpointGroup.ofWatcher(
          watcher, EndpointListDecoder.TEXT);
      endpointGroup.awaitInitialEndpoints();
      assertThat(endpointGroup.endpoints()).isEqualTo(ENDPOINT_LIST);
      assertThat(latch.getCount()).isOne();

      dogma.client().push("directory", "my-service",
                Revision.HEAD, "commit",
                Change.ofTextUpsert("/endpoints.txt", "foo.bar:1234"))
         .join();

      await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> assertThat(latch.getCount()).isZero());
      assertThat(endpointGroup.endpoints()).containsExactly(Endpoint.of("foo.bar", 1234));
    }
  }
}

相关文章