Class ServiceFactoryFactory
- java.lang.Object
-
- com.google.appengine.spi.ServiceFactoryFactory
-
public final class ServiceFactoryFactory extends Object
This class is not intended for end users.Provide factory instances for AppEngine APIs. Each API will have an associated
FactoryProvider
registered with this class. N.B. OncegetFactory(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 registeredFactoryProvider
entities using theClassLoader
ofServiceFactoryFactory
. Finally, the explicitly registered providersregister(FactoryProvider)
are merged in.If
ServiceLoader
locates multiple providers for a given factory interface, the ambiguity can be resolved by using theServiceProvider.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 theServiceProvider.precedence()
annotation property).
-
-
Field Summary
Fields Modifier and Type Field Description static 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 Summary
Constructors Constructor Description ServiceFactoryFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
getFactory(Class<T> base)
Used by AppEngine service factories.static <I> void
register(FactoryProvider<I> p)
Explicitly register a provider.
-
-
-
Field Detail
-
USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY
public static final 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. Otherwise the class loader of this class is used.- See Also:
- Constant Field Values
-
-
Method Detail
-
getFactory
public static <T> T getFactory(Class<T> base)
Used by AppEngine service factories. Returns an instance of the factory implementing the interface provide bybase
. Since there must always be a provider registered for a given base, an error will be raised if no appropriate registration is found.- Type Parameters:
T
- The type of the factory- Parameters:
base
- The returned factory must extend this class.- Throws:
IllegalArgumentException
- raised if the client requests a factory that does not have a provider registered for it.ServiceConfigurationError
- raised if there is a problem creating the factory instance
-
register
public static <I> void register(FactoryProvider<I> p)
Explicitly register a provider. This does not take the precedence (seeFactoryProvider.getPrecedence()
) of the provider into consideration; subsequent registrations will always override previous ones.- Parameters:
p
- The provider to register- Throws:
IllegalStateException
- raised if calls to getFactoryProvider have already been made.
-
-