Module java.desktop

Class ServiceRegistry

Direct Known Subclasses:

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: