ManagedChannelProvider { @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(); } }); } }  static ManagedChannelProvider provider();  }
@Test public void multipleProvider() { ClassLoader cl = new ServicesClassLoader(getClass().getClassLoader(), "io/grpc/ManagedChannelProviderTest-multipleProvider.txt"); assertSame(Available7Provider.class, ManagedChannelProvider.load(cl).getClass()); }
@Test public void unavailableProvider() { ClassLoader cl = new ServicesClassLoader(getClass().getClassLoader(), "io/grpc/ManagedChannelProviderTest-unavailableProvider.txt"); assertNull(ManagedChannelProvider.load(cl)); }