Package io.grpc
Class ServiceProviders
- java.lang.Object
-
- io.grpc.ServiceProviders
-
final class ServiceProviders extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceServiceProviders.PriorityAccessor<T>An interface that allows us to get priority information about a provider.
-
Constructor Summary
Constructors Modifier Constructor Description privateServiceProviders()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static <T> TcreateForHardCoded(java.lang.Class<T> klass, java.lang.Class<?> rawClass)(package private) static <T> java.lang.Iterable<T>getCandidatesViaHardCoded(java.lang.Class<T> klass, java.lang.Iterable<java.lang.Class<?>> hardcoded)Load providers from a hard-coded list.static <T> java.lang.Iterable<T>getCandidatesViaServiceLoader(java.lang.Class<T> klass, java.lang.ClassLoader cl)Loads service providers for theklassservice usingServiceLoader.(package private) static booleanisAndroid(java.lang.ClassLoader cl)Returns true if theClassLoaderis for android.static <T> Tload(java.lang.Class<T> klass, java.lang.Iterable<java.lang.Class<?>> hardcoded, java.lang.ClassLoader cl, ServiceProviders.PriorityAccessor<T> priorityAccessor)If this is not Android, returns the highest priority implementation of the class viaServiceLoader.static <T> java.util.List<T>loadAll(java.lang.Class<T> klass, java.lang.Iterable<java.lang.Class<?>> hardcoded, java.lang.ClassLoader cl, ServiceProviders.PriorityAccessor<T> priorityAccessor)If this is not Android, returns all available implementations discovered viaServiceLoader.
-
-
-
Method Detail
-
load
public static <T> T load(java.lang.Class<T> klass, java.lang.Iterable<java.lang.Class<?>> hardcoded, java.lang.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> java.util.List<T> loadAll(java.lang.Class<T> klass, java.lang.Iterable<java.lang.Class<?>> hardcoded, java.lang.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
static boolean isAndroid(java.lang.ClassLoader cl)
Returns true if theClassLoaderis for android.
-
getCandidatesViaServiceLoader
public static <T> java.lang.Iterable<T> getCandidatesViaServiceLoader(java.lang.Class<T> klass, java.lang.ClassLoader cl)Loads service providers for theklassservice usingServiceLoader.
-
getCandidatesViaHardCoded
static <T> java.lang.Iterable<T> getCandidatesViaHardCoded(java.lang.Class<T> klass, java.lang.Iterable<java.lang.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).
-
createForHardCoded
private static <T> T createForHardCoded(java.lang.Class<T> klass, java.lang.Class<?> rawClass)
-
-