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

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

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

  1. /**
  2. * Creates a new host {@link Endpoint}.
  3. *
  4. * @deprecated Use {@link #of(String, int)} and {@link #withWeight(int)},
  5. * e.g. {@code Endpoint.of("foo.com", 80).withWeight(500)}.
  6. */
  7. @Deprecated
  8. public static Endpoint of(String host, int port, int weight) {
  9. return of(host, port).withWeight(weight);
  10. }

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

  1. switch (tokens.length) {
  2. case 1: //host
  3. endpoint = Endpoint.of(segment);
  4. break;
  5. case 2: { //host and port
  6. final int port = Integer.parseInt(tokens[1]);
  7. if (port == 0) {
  8. endpoint = Endpoint.of(host);
  9. } else {
  10. endpoint = Endpoint.of(host, port);
  11. final int weight = Integer.parseInt(tokens[2]);
  12. if (port == 0) {
  13. endpoint = Endpoint.of(host).withWeight(weight);
  14. } else {
  15. endpoint = Endpoint.of(host, port).withWeight(weight);

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

  1. @Override
  2. public void serverStarted(Server server) throws Exception {
  3. if (endpoint == null) {
  4. assert server.activePort().isPresent();
  5. endpoint = Endpoint.of(server.defaultHostname(),
  6. server.activePort().get()
  7. .localAddress().getPort());
  8. }
  9. client.start();
  10. final String key = endpoint.host() + '_' + endpoint.port();
  11. final byte[] value = nodeValueCodec.encode(endpoint);
  12. client.create()
  13. .creatingParentsIfNeeded()
  14. .withMode(CreateMode.EPHEMERAL)
  15. .forPath(zNodePath + '/' + key, value);
  16. }

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

  1. @Test
  2. public void convert() {
  3. assertThat(NodeValueCodec.DEFAULT
  4. .decodeAll("foo.com, bar.com:8080, 10.0.2.15:0:500, 192.168.1.2:8443:700"))
  5. .containsExactlyInAnyOrder(Endpoint.of("foo.com"),
  6. Endpoint.of("bar.com", 8080),
  7. Endpoint.of("10.0.2.15").withWeight(500),
  8. Endpoint.of("192.168.1.2", 8443).withWeight(700));
  9. assertThatThrownBy(() -> NodeValueCodec.DEFAULT
  10. .decodeAll("http://foo.com:8001, bar.com:8002"))
  11. .isInstanceOf(EndpointGroupException.class);
  12. }
  13. }

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

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

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

  1. @Test
  2. public void urlAnnotation_uriWithoutScheme() throws Exception {
  3. EndpointGroupRegistry.register("bar",
  4. new StaticEndpointGroup(Endpoint.of("127.0.0.1", server.httpPort())),
  5. ROUND_ROBIN);
  6. assertThat(service.fullUrl("//localhost:" + server.httpPort() + "/nest/pojo").get()).isEqualTo(
  7. new Pojo("Leonard", 21));
  8. assertThat(service.fullUrl("//group_bar/nest/pojo").get()).isEqualTo(new Pojo("Leonard", 21));
  9. assertThat(service.fullUrl("//localhost:" + server.httpPort() + "/pojo").get()).isEqualTo(
  10. new Pojo("Cony", 26));
  11. assertThat(service.fullUrl("//group_bar/pojo").get()).isEqualTo(new Pojo("Cony", 26));
  12. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

代码示例来源: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. @Test(timeout = 10000)
  2. public void text() throws Exception {
  3. try (Watcher<String> watcher = dogma.client().fileWatcher("directory", "my-service",
  4. Query.ofText("/endpoints.txt"))) {
  5. final CountDownLatch latch = new CountDownLatch(2);
  6. watcher.watch(unused -> latch.countDown());
  7. final CentralDogmaEndpointGroup<String> endpointGroup = CentralDogmaEndpointGroup.ofWatcher(
  8. watcher, EndpointListDecoder.TEXT);
  9. endpointGroup.awaitInitialEndpoints();
  10. assertThat(endpointGroup.endpoints()).isEqualTo(ENDPOINT_LIST);
  11. assertThat(latch.getCount()).isOne();
  12. dogma.client().push("directory", "my-service",
  13. Revision.HEAD, "commit",
  14. Change.ofTextUpsert("/endpoints.txt", "foo.bar:1234"))
  15. .join();
  16. await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> assertThat(latch.getCount()).isZero());
  17. assertThat(endpointGroup.endpoints()).containsExactly(Endpoint.of("foo.bar", 1234));
  18. }
  19. }
  20. }

相关文章