Module java.desktop

Class ServiceRegistry

java.lang.Object
javax.imageio.spi.ServiceRegistry
Direct Known Subclasses:
IIORegistry

public class ServiceRegistry extends Object
A registry for service provider instances for Image I/O service types.

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 Classes
    Modifier and Type
    Class
    Description
    static interface 
    A simple filter interface used by ServiceRegistry.getServiceProviders to select providers matching an arbitrary criterion.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServiceRegistry​(Iterator<Class<?>> categories)
    Constructs a ServiceRegistry instance with a set of categories taken from the categories argument.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains​(Object provider)
    Returns true if provider 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
    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
    Deprecated.
    The finalize method has been deprecated.
    Returns an Iterator of Class 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 an Iterator containing all registered service providers in the given category.
    <T> Iterator<T>
    getServiceProviders​(Class<T> category, ServiceRegistry.Filter filter, boolean useOrdering)
    Returns an Iterator containing service provider objects within a given category that satisfy a criterion imposed by the supplied ServiceRegistry.Filter object's filter 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
    Adds a service provider object to the registry.
    <T> boolean