- Direct Known Subclasses:
IIORegistry
Service providers are stored in one or more categories,
each of which is defined by a class or interface (described by a
Class
object) that all of its members must implement.
The set of categories supported by this class is limited to the following standard Image I/O service types:
An attempt to load a provider that is not a subtype of one of the
above types will result in IllegalArgumentException
.
For the general mechanism to load service providers, see
ServiceLoader
, which is
the underlying standard mechanism used by this class.
Only a single instance of a given leaf class (that is, the
actual class returned by getClass()
, as opposed to any
inherited classes or interfaces) may be registered. That is,
suppose that the
com.mycompany.mypkg.GreenImageReaderProvider
class
is a subclass of javax.imageio.spi.ImageReaderSpi
.
If a GreenImageReaderProvider
instance is
registered, it will be stored in the category defined by the
ImageReaderSpi
class. If a new instance of
GreenImageReaderProvider
is registered, it will replace
the previous instance. In practice, service provider objects are
usually singletons so this behavior is appropriate.
The service provider classes should be lightweight and quick to load. Implementations of these interfaces should avoid complex dependencies on other classes and on native code. The usual pattern for more complex services is to register a lightweight proxy for the heavyweight service.
An application may customize the contents of a registry as it sees fit, so long as it has the appropriate runtime permission.
For information on how to create and deploy service providers,
refer to the documentation on ServiceLoader
- See Also:
RegisterableService
,ServiceLoader
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
A simple filter interface used byServiceRegistry.getServiceProviders
to select providers matching an arbitrary criterion. -
Constructor Summary
ConstructorsConstructorDescriptionServiceRegistry(Iterator<Class<?>> categories)
Constructs aServiceRegistry
instance with a set of categories taken from thecategories
argument. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
ifprovider
is currently registered.void
Deregisters all currently registered service providers from all categories.void
deregisterAll(Class<?> category)
Deregisters all service provider object currently registered under the given category.void
deregisterServiceProvider(Object provider)
Removes a service provider object from all categories that contain it.<T> boolean
deregisterServiceProvider(T provider, Class<T> category)
Removes a service provider object from the given category.void
finalize()
Deprecated.Returns anIterator
ofClass
objects indicating the current set of categories.<T> T
getServiceProviderByClass(Class<T> providerClass)
Returns the currently registered service provider object that is of the given class type.<T> Iterator<T>
getServiceProviders(Class<T> category, boolean useOrdering)
Returns anIterator
containing all registered service providers in the given category.<T> Iterator<T>
getServiceProviders(Class<T> category, ServiceRegistry.Filter filter, boolean useOrdering)
Returns anIterator
containing service provider objects within a given category that satisfy a criterion imposed by the suppliedServiceRegistry.Filter
object'sfilter
method.static <T> Iterator<T>
lookupProviders(Class<T> providerClass)
Locates and incrementally instantiates the available providers of a given service using the context class loader.static <T> Iterator<T>
lookupProviders(Class<T> providerClass, ClassLoader loader)
Searches for implementations of a particular service class using the given class loader.void
registerServiceProvider(Object provider)
Adds a service provider object to the registry.<T> boolean
finalize
method has been deprecated.