Top Inners Constructors Methods
io.grpc

pack-priv final Class ServiceProviders

extends Object
Class Inheritance
Imports
com.google.common.annotations.VisibleForTesting, java.util.ArrayList, .Collections, .Comparator, .List, .ServiceConfigurationError, .ServiceLoader

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ServiceProviders.PriorityAccessor<T>

An interface that allows us to get priority information about a provider.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static <T> T
createForHardCoded(Class<T> klass, Class<?> rawClass)

pack-priv static <T> Iterable<T>
getCandidatesViaHardCoded(Class<T> klass, Iterable<Class<?>> hardcoded)

Load providers from a hard-coded list.

public static <T> Iterable<T>
getCandidatesViaServiceLoader(Class<T> klass, ClassLoader cl)

Loads service providers for the klass service using ServiceLoader.

pack-priv static boolean
isAndroid(ClassLoader cl)

Returns true if the ClassLoader is for android.

public static <T> T
load(Class<T> klass, Iterable<Class<?>> hardcoded, ClassLoader cl, ServiceProviders.PriorityAccessor<T> priorityAccessor)

If this is not Android, returns the highest priority implementation of the class via ServiceLoader.

public static <T> List<T>
loadAll(Class<T> klass, Iterable<Class<?>> hardcoded, ClassLoader cl, final ServiceProviders.PriorityAccessor<T> priorityAccessor)

If this is not Android, returns all available implementations discovered via ServiceLoader.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ServiceProvidersback to summary
private ServiceProviders()

Method Detail

createForHardCodedback to summary
private static <T> T createForHardCoded(Class<T> klass, Class<?> rawClass)
getCandidatesViaHardCodedback to summary
pack-priv static <T> Iterable<T> getCandidatesViaHardCoded(Class<T> klass, Iterable<Class<?>> hardcoded)

Load providers from a hard-coded list. This avoids using getResource(), which has performance problems on Android (see https://github.com/grpc/grpc-java/issues/2037).

Annotations
@VisibleForTesting
getCandidatesViaServiceLoaderback to summary
public static <T> Iterable<T> getCandidatesViaServiceLoader(Class<T> klass, ClassLoader cl)

Loads service providers for the klass service using ServiceLoader.

Annotations
@VisibleForTesting
isAndroidback to summary
pack-priv static boolean isAndroid(ClassLoader cl)

Returns true if the ClassLoader is for android.

loadback to summary
public static <T> T load(Class<T> klass, Iterable<Class<?>> hardcoded, ClassLoader cl, ServiceProviders.PriorityAccessor<T> priorityAccessor)

If this is not Android, returns the highest priority implementation of the class via ServiceLoader. If this is Android, returns an instance of the highest priority class in hardcoded.

loadAllback to summary
public static <T> List<T> loadAll(Class<T> klass, Iterable<Class<?>> hardcoded, ClassLoader cl, final ServiceProviders.PriorityAccessor<T> priorityAccessor)

If this is not Android, returns all available implementations discovered via ServiceLoader. If this is Android, returns all available implementations in hardcoded. The list is sorted in descending priority order.

io.grpc back to summary

public Interface ServiceProviders.PriorityAccessor<T>

Known Direct Subinterfaces
io.grpc.InternalServiceProviders.PriorityAccessor
Known Direct Implementers
io.grpc.LoadBalancerRegistry.LoadBalancerPriorityAccessor, io.grpc.ManagedChannelRegistry.ManagedChannelPriorityAccessor, io.grpc.NameResolverRegistry.NameResolverPriorityAccessor, io.grpc.ServerRegistry.ServerPriorityAccessor

An interface that allows us to get priority information about a provider.

Method Summary

Modifier and TypeMethod and Description
public int
getPriority(T provider)

A priority, from 0 to 10 that this provider should be used, taking the current environment into consideration.

public boolean
isAvailable(T provider)

Checks this provider is available for use, taking the current environment into consideration.

Method Detail

getPriorityback to summary
public int getPriority(T provider)

A priority, from 0 to 10 that this provider should be used, taking the current environment into consideration. 5 should be considered the default, and then tweaked based on environment detection. A priority of 0 does not imply that the provider wouldn't work; just that it should be last in line.

isAvailableback to summary
public boolean isAvailable(T provider)

Checks this provider is available for use, taking the current environment into consideration. If false, no other methods are safe to be called.