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

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

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

Endpoint.authority介绍

[英]Converts this endpoint into the authority part of a URI.
[中]将此端点转换为URI的授权部分。

代码示例

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

  1. @Override
  2. public int hashCode() {
  3. return (authority().hashCode() * 31 + Objects.hashCode(ipAddr)) * 31 + port;
  4. }

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

  1. private State state(Endpoint endpoint) {
  2. final String authority = endpoint.authority();
  3. return map.computeIfAbsent(authority, e -> new State(eventLoops));
  4. }

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

  1. @Override
  2. public String toString() {
  3. final ToStringHelper helper = MoreObjects.toStringHelper(this);
  4. helper.addValue(authority());
  5. if (!isGroup()) {
  6. if (hostType == HostType.HOSTNAME_AND_IPv4 ||
  7. hostType == HostType.HOSTNAME_AND_IPv6) {
  8. helper.add("ipAddr", ipAddr);
  9. }
  10. helper.add("weight", weight);
  11. }
  12. return helper.toString();
  13. }
  14. }

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

  1. @Override
  2. public String toString() {
  3. String strVal = this.strVal;
  4. if (strVal != null) {
  5. return strVal;
  6. }
  7. final StringBuilder buf = new StringBuilder(96);
  8. // Prepend the current channel information if available.
  9. final Channel ch = channel();
  10. final boolean hasChannel = ch != null;
  11. if (hasChannel) {
  12. buf.append(ch);
  13. }
  14. buf.append('[')
  15. .append(sessionProtocol().uriText())
  16. .append("://")
  17. .append(endpoint.authority())
  18. .append(path())
  19. .append('#')
  20. .append(method())
  21. .append(']');
  22. strVal = buf.toString();
  23. if (hasChannel) {
  24. this.strVal = strVal;
  25. }
  26. return strVal;
  27. }

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

  1. @Override
  2. public void accept(List<Endpoint> endpoints) {
  3. final Map<Endpoint, Boolean> endpointsToUpdate = new HashMap<>();
  4. endpoints.forEach(e -> endpointsToUpdate.put(e, true));
  5. endpointGroup.allServers.forEach(
  6. conn -> endpointsToUpdate.putIfAbsent(conn.endpoint(), false));
  7. // Update the previously appeared endpoints.
  8. healthMap.entrySet().forEach(e -> {
  9. final Endpoint authority = e.getKey();
  10. final Boolean healthy = endpointsToUpdate.remove(authority);
  11. e.setValue(Boolean.TRUE.equals(healthy));
  12. });
  13. // Process the newly appeared endpoints.
  14. endpointsToUpdate.forEach((endpoint, healthy) -> {
  15. healthMap.put(endpoint, healthy);
  16. final List<Tag> tags = new ArrayList<>(2);
  17. tags.add(Tag.of("authority", endpoint.authority()));
  18. final String ipAddr = endpoint.hasIpAddr() ? endpoint.ipAddr() : "";
  19. assert ipAddr != null;
  20. tags.add(Tag.of("ip", ipAddr));
  21. registry.gauge(idPrefix.name(), idPrefix.tags(tags),
  22. this, unused -> healthMap.get(endpoint) ? 1 : 0);
  23. });
  24. }
  25. }

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

  1. logPrefix(),
  2. endpoints.stream()
  3. .map(e -> e.authority() + '/' + e.weight())
  4. .collect(Collectors.joining(", ")),
  5. ttl);

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

  1. private HttpEndpointHealthChecker(
  2. ClientFactory clientFactory, Endpoint endpoint,
  3. SessionProtocol protocol, String healthCheckPath, int healthCheckPort,
  4. Function<? super ClientOptionsBuilder, ClientOptionsBuilder> configurator) {
  5. final String scheme = protocol.uriText();
  6. final String ipAddr = endpoint.ipAddr();
  7. final HttpClientBuilder builder;
  8. if (ipAddr == null) {
  9. builder = new HttpClientBuilder(scheme + "://" + endpoint.authority());
  10. } else {
  11. final int port = healthCheckPort > 0 ? healthCheckPort : endpoint.port(protocol.defaultPort());
  12. if (endpoint.ipFamily() == StandardProtocolFamily.INET) {
  13. builder = new HttpClientBuilder(scheme + "://" + ipAddr + ':' + port);
  14. } else {
  15. builder = new HttpClientBuilder(scheme + "://[" + ipAddr + "]:" + port);
  16. }
  17. builder.setHttpHeader(HttpHeaderNames.AUTHORITY, endpoint.authority());
  18. }
  19. httpClient = builder.factory(clientFactory)
  20. .options(configurator.apply(new ClientOptionsBuilder()).build())
  21. .build();
  22. this.healthCheckPath = healthCheckPath;
  23. }

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

  1. final Endpoint endpoint = cCtx.endpoint();
  2. if (endpoint.isGroup()) {
  3. authority = endpoint.authority();
  4. } else {
  5. final int defaultPort = cCtx.sessionProtocol().defaultPort();

代码示例来源:origin: com.linecorp.armeria/armeria-logback

  1. final Endpoint endpoint = cCtx.endpoint();
  2. if (endpoint.isGroup()) {
  3. authority = endpoint.authority();
  4. } else {
  5. final int defaultPort = cCtx.sessionProtocol().defaultPort();

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

  1. final Endpoint endpoint = cCtx.endpoint();
  2. if (endpoint.isGroup()) {
  3. authority = endpoint.authority();
  4. } else {
  5. final int defaultPort = cCtx.sessionProtocol().defaultPort();

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

  1. /**
  2. * Returns a newly-created {@link CentralDogma} instance.
  3. *
  4. * @throws UnknownHostException if failed to resolve the host names from the DNS servers
  5. */
  6. public CentralDogma build() throws UnknownHostException {
  7. final Endpoint endpoint = endpoint();
  8. final String scheme = "tbinary+" + (isUseTls() ? "https" : "http") + "://";
  9. final String uri = scheme + endpoint.authority() + "/cd/thrift/v1";
  10. final ClientBuilder builder = new ClientBuilder(uri)
  11. .factory(clientFactory())
  12. .rpcDecorator(CentralDogmaClientTimeoutScheduler::new);
  13. clientConfigurator().configure(builder);
  14. builder.decorator((delegate, ctx, req) -> {
  15. if (!req.headers().contains(HttpHeaderNames.AUTHORIZATION)) {
  16. // To prevent CSRF attack, we add 'Authorization' header to every request.
  17. req.headers().set(HttpHeaderNames.AUTHORIZATION, "bearer " + CsrfToken.ANONYMOUS);
  18. }
  19. return delegate.execute(ctx, req);
  20. });
  21. return new LegacyCentralDogma(clientFactory(), builder.build(CentralDogmaService.AsyncIface.class));
  22. }
  23. }

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

  1. /**
  2. * Returns a newly-created {@link CentralDogma} instance.
  3. *
  4. * @throws UnknownHostException if failed to resolve the host names from the DNS servers
  5. */
  6. public CentralDogma build() throws UnknownHostException {
  7. final Endpoint endpoint = endpoint();
  8. final String scheme = "tbinary+" + (isUseTls() ? "https" : "http") + "://";
  9. final String uri = scheme + endpoint.authority() + "/cd/thrift/v1";
  10. final ClientBuilder builder = new ClientBuilder(uri)
  11. .factory(clientFactory())
  12. .decorator(RpcRequest.class, RpcResponse.class,
  13. CentralDogmaClientTimeoutScheduler::new);
  14. clientConfigurator().configure(builder);
  15. builder.decorator(HttpRequest.class, HttpResponse.class,
  16. (delegate, ctx, req) -> {
  17. if (!req.headers().contains(HttpHeaderNames.AUTHORIZATION)) {
  18. // To prevent CSRF attack, we add 'Authorization' header to every request.
  19. req.headers().set(HttpHeaderNames.AUTHORIZATION,
  20. "bearer " + CsrfToken.ANONYMOUS);
  21. }
  22. return delegate.execute(ctx, req);
  23. });
  24. return new LegacyCentralDogma(clientFactory(), builder.build(CentralDogmaService.AsyncIface.class));
  25. }
  26. }

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

  1. /**
  2. * Returns a newly-created {@link CentralDogma} instance.
  3. *
  4. * @throws UnknownHostException if failed to resolve the host names from the DNS servers
  5. */
  6. public CentralDogma build() throws UnknownHostException {
  7. final Endpoint endpoint = endpoint();
  8. final String scheme = "tbinary+" + (isUseTls() ? "https" : "http") + "://";
  9. final String uri = scheme + endpoint.authority() + "/cd/thrift/v1";
  10. final ClientBuilder builder = new ClientBuilder(uri)
  11. .factory(clientFactory())
  12. .rpcDecorator(CentralDogmaClientTimeoutScheduler::new);
  13. clientConfigurator().configure(builder);
  14. builder.decorator((delegate, ctx, req) -> {
  15. if (!req.headers().contains(HttpHeaderNames.AUTHORIZATION)) {
  16. // To prevent CSRF attack, we add 'Authorization' header to every request.
  17. req.headers().set(HttpHeaderNames.AUTHORIZATION, "bearer " + CsrfToken.ANONYMOUS);
  18. }
  19. return delegate.execute(ctx, req);
  20. });
  21. return new LegacyCentralDogma(clientFactory(), builder.build(CentralDogmaService.AsyncIface.class));
  22. }
  23. }

相关文章