コード例 #1
0
  @Override
  public List<URI> selectHttpService() {
    List<ServiceDescriptor> serviceDescriptors =
        Lists.newArrayList(serviceSelector.selectAllServices());
    if (serviceDescriptors.isEmpty()) {
      return ImmutableList.of();
    }

    // favor https over http
    List<URI> httpsUri = Lists.newArrayList();
    for (ServiceDescriptor serviceDescriptor : serviceDescriptors) {
      String https = serviceDescriptor.getProperties().get("https");
      if (https != null) {
        try {
          httpsUri.add(new URI(https));
        } catch (URISyntaxException ignored) {
        }
      }
    }
    List<URI> httpUri = Lists.newArrayList();
    for (ServiceDescriptor serviceDescriptor : serviceDescriptors) {
      String http = serviceDescriptor.getProperties().get("http");
      if (http != null) {
        try {
          httpUri.add(new URI(http));
        } catch (URISyntaxException ignored) {
        }
      }
    }

    // return random(https) + random(http)
    Collections.shuffle(httpsUri);
    Collections.shuffle(httpUri);
    return ImmutableList.<URI>builder().addAll(httpsUri).addAll(httpUri).build();
  }