public final class ServiceFactoryFactory
extends java.lang.Object
Provide factory instances for AppEngine APIs. Each API will have an associated
FactoryProvider
registered with this class. N.B. Once getFactory(Class)
has
been called, no further mappings may be registered with this class.
To construct the runtime mapping, this class first uses java.util.ServiceLoader
to
find all registered FactoryProvider
entities using the ClassLoader
of
ServiceFactoryFactory
. Finally, the explicitly registered providers
register(FactoryProvider)
are merged in.
If ServiceLoader
locates multiple providers for a given factory interface, the
ambiguity can be resolved by using the ServiceProvider.precedence()
annotation property
(higher precedence wins; the google implementations all have precedence
Integer.MIN_VALUE). An exception is raised if the ambiguity cannot be resolved. Note that
explicit registration (register(FactoryProvider)
) always takes precedence (it does not
honor the ServiceProvider.precedence()
annotation property).
Authors of FactoryProvider
s are encouraged to leverage ServiceProvider
and
ServiceProviderProcessor
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY
If this system property is set to "true" the thread context classloader is used (if non-null)
when looking up API service implementations.
|
Constructor and Description |
---|
ServiceFactoryFactory() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
getFactory(java.lang.Class<T> base)
Used by AppEngine service factories.
|
static <I> void |
register(FactoryProvider<I> p)
Explicitly register a provider.
|
public static final java.lang.String USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY
public static <T> T getFactory(java.lang.Class<T> base)
base
. Since there must always be a provider registered for a given
base, an error will be raised if no appropriate registration is found.T
- The type of the factorybase
- The returned factory must extend this class.java.lang.IllegalArgumentException
- raised if the client requests a factory that does not have a
provider registered for it.java.util.ServiceConfigurationError
- raised if there is a problem creating the factory instancepublic static <I> void register(FactoryProvider<I> p)
FactoryProvider.getPrecedence()
) of the provider into consideration; subsequent
registrations will always override previous ones.p
- The provider to registerjava.lang.IllegalStateException
- raised if calls to getFactoryProvider have already been made.