Package io.grpc
Class ServiceProviders
java.lang.Object
io.grpc.ServiceProviders
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An interface that allows us to get priority information about a provider. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> T
createForHardCoded
(Class<T> klass, Class<?> rawClass) (package private) static <T> Iterable
<T> getCandidatesViaHardCoded
(Class<T> klass, Iterable<Class<?>> hardcoded) Load providers from a hard-coded list.static <T> Iterable
<T> getCandidatesViaServiceLoader
(Class<T> klass, ClassLoader cl) Loads service providers for theklass
service usingServiceLoader
.(package private) static boolean
isAndroid
(ClassLoader cl) Returns true if theClassLoader
is for android.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 viaServiceLoader
.static <T> List
<T> loadAll
(Class<T> klass, Iterable<Class<?>> hardcoded, ClassLoader cl, ServiceProviders.PriorityAccessor<T> priorityAccessor) If this is not Android, returns all available implementations discovered viaServiceLoader
.
-
Constructor Details
-
ServiceProviders
private ServiceProviders()
-
-
Method Details
-
load
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 viaServiceLoader
. If this is Android, returns an instance of the highest priority class inhardcoded
. -
loadAll
public static <T> List<T> loadAll(Class<T> klass, Iterable<Class<?>> hardcoded, ClassLoader cl, ServiceProviders.PriorityAccessor<T> priorityAccessor) If this is not Android, returns all available implementations discovered viaServiceLoader
. If this is Android, returns all available implementations inhardcoded
. The list is sorted in descending priority order. -
isAndroid
Returns true if theClassLoader
is for android. -
getCandidatesViaServiceLoader
Loads service providers for theklass
service usingServiceLoader
. -
getCandidatesViaHardCoded
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). -
createForHardCoded
-