com.linecorp.armeria.server.VirtualHost.serviceConfigs()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(126)

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

VirtualHost.serviceConfigs介绍

[英]Returns the information about the Services bound to this virtual host.
[中]返回有关绑定到此虚拟主机的服务的信息。

代码示例

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

/**
 * Finds the {@link List} of {@link VirtualHost}s that contains the specified {@link Service}. If there's
 * no match, an empty {@link List} is returned. Note that this is potentially an expensive operation and
 * thus should not be used in a performance-sensitive path.
 */
public List<VirtualHost> findVirtualHosts(Service<?, ?> service) {
  requireNonNull(service, "service");
  @SuppressWarnings("rawtypes")
  final Class<? extends Service> serviceType = service.getClass();
  final List<VirtualHost> res = new ArrayList<>();
  for (VirtualHost h : virtualHosts) {
    for (ServiceConfig c : h.serviceConfigs()) {
      // Consider the case where the specified service is decorated before being added.
      final Service<?, ?> s = c.service();
      @SuppressWarnings("rawtypes")
      final Optional<? extends Service> sOpt = s.as(serviceType);
      if (!sOpt.isPresent()) {
        continue;
      }
      if (sOpt.get() == service) {
        res.add(c.virtualHost());
        break;
      }
    }
  }
  return res;
}

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

private static ServiceConfig findServiceConfig(Server server, String path, Service<?, ?> service) {
    for (ServiceConfig cfg : server.config().defaultVirtualHost().serviceConfigs()) {
      final Optional<String> exactPath = cfg.pathMapping().exactPath();
      if (!exactPath.isPresent()) {
        continue;
      }

      if (!path.equals(exactPath.get())) {
        continue;
      }

      if (cfg.service().as(service.getClass()).isPresent()) {
        return cfg;
      }
    }

    throw new Error(); // Never reaches here.
  }
}

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

@Override
public String toString() {
  String strVal = this.strVal;
  if (strVal == null) {
    this.strVal = strVal = toString(
        getClass(), defaultHostname(), hostnamePattern(), sslContext(), serviceConfigs());
  }
  return strVal;
}

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

private VirtualHost normalizeDefaultVirtualHost(VirtualHost h,
                        @Nullable SslContext defaultSslContext) {
  final SslContext sslCtx = h.sslContext() != null ? h.sslContext() : defaultSslContext;
  return new VirtualHost(
      h.defaultHostname(), "*", sslCtx,
      h.serviceConfigs().stream().map(
          e -> new ServiceConfig(e.pathMapping(), e.service(), e.loggerName().orElse(null)))
       .collect(Collectors.toList()), h.producibleMediaTypes(),
           rejectedPathMappingHandler, host -> h.accessLogger());
}

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

if (virtualHostsCopy.stream().allMatch(h -> h.serviceConfigs().isEmpty())) {
  throw new IllegalArgumentException("no services in the server");
              .flatMap(h -> h.serviceConfigs().stream())
              .collect(toImmutableList());

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

virtualHosts.forEach(c -> {
  buf.append(VirtualHost.toString(null, c.defaultHostname(), c.hostnamePattern(),
                  c.sslContext(), c.serviceConfigs()));
  buf.append(", ");
});
  buf.append(VirtualHost.toString(null, defaultVirtualHost.defaultHostname(), "*",
                  defaultVirtualHost.sslContext(),
                  defaultVirtualHost.serviceConfigs()));
} else {
  buf.setLength(buf.length() - 2);
buf.append(VirtualHost.toString(null, defaultVirtualHost.defaultHostname(), "*",
                defaultVirtualHost.sslContext(),
                defaultVirtualHost.serviceConfigs()));

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

private static Service<?, ?> service(ServerBuilder sb) {
  final Server server = sb.build();
  return server.config().defaultVirtualHost().serviceConfigs().get(0).service();
}

相关文章