@VisibleForTesting
 static ManagedChannelProvider load(ClassLoader classLoader) {
   ServiceLoader<ManagedChannelProvider> providers =
       ServiceLoader.load(ManagedChannelProvider.class, classLoader);
   List<ManagedChannelProvider> list = new ArrayList<ManagedChannelProvider>();
   for (ManagedChannelProvider current : providers) {
     if (!current.isAvailable()) {
       continue;
     }
     list.add(current);
   }
   if (list.isEmpty()) {
     return null;
   } else {
     return Collections.max(
         list,
         new Comparator<ManagedChannelProvider>() {
           @Override
           public int compare(ManagedChannelProvider f1, ManagedChannelProvider f2) {
             return f1.priority() - f2.priority();
           }
         });
   }
 }
 public static ManagedChannelBuilder<?> forAddress(String name, int port) {
   return ManagedChannelProvider.provider().builderForAddress(name, port);
 }
Exemplo n.º 3
0
 /**
  * Creates a channel with a target string, which can be either a valid {@link
  * NameResolver}-compliant URI, or an authority string.
  *
  * <p>A {@code NameResolver}-compliant URI is an absolute hierarchical URI as defined by {@link
  * java.net.URI}. Example URIs:
  *
  * <ul>
  *   <li>{@code "dns:///foo.googleapis.com:8080"}
  *   <li>{@code "dns:///foo.googleapis.com"}
  *   <li>{@code "dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443"}
  *   <li>{@code "dns://8.8.8.8/foo.googleapis.com:8080"}
  *   <li>{@code "dns://8.8.8.8/foo.googleapis.com"}
  *   <li>{@code "zookeeper://zk.example.com:9900/example_service"}
  * </ul>
  *
  * <p>An authority string will be converted to a {@code NameResolver}-compliant URI, which has
  * {@code "dns"} as the scheme, no authority, and the original authority string as its path after
  * properly escaped. Example authority strings:
  *
  * <ul>
  *   <li>{@code "localhost"}
  *   <li>{@code "127.0.0.1"}
  *   <li>{@code "localhost:8080"}
  *   <li>{@code "foo.googleapis.com:8080"}
  *   <li>{@code "127.0.0.1:8080"}
  *   <li>{@code "[2001:db8:85a3:8d3:1319:8a2e:370:7348]"}
  *   <li>{@code "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443"}
  * </ul>
  */
 @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1773")
 public static ManagedChannelBuilder<?> forTarget(String target) {
   return ManagedChannelProvider.provider().builderForTarget(target);
 }