T- The type of extension factory
S- the type of configuration to be used when creating the extension
@NotThreadSafe public class ExtensionFactoryRegistry<T extends ExtensionFactory<?,S>,S extends AlluxioConfiguration> extends Object
An extension registry that uses the
ServiceLoader mechanism to automatically discover
available factories and provides a central place for obtaining actual extension instances.
New factories can be registered either using the ServiceLoader based automatic
discovery mechanism or manually using the static
method. The down-side of the automatic discovery mechanism is that the discovery order is not
controllable. As a result if your implementation is designed as a replacement for one of the
standard implementations, depending on the order in which the JVM discovers the services your own
implementation may not take priority. You can enable
DEBUG level logging for this class
to see the order in which factories are discovered and which is selected when obtaining a
T instance for a path. If this shows that your implementation is not
getting discovered or used, you may wish to use the manual registration approach.
To use the ServiceLoader based mechanism you need to have a file with the same name
as the factory class
T placed in the
of your project. This file should contain the full name of your factory types (one per line),
your factory types must have a public unparameterised constructor available (see
ServiceLoader for more detail on this). You can enable
DEBUG level logging to see
factories as they are discovered if you wish to check that your implementation gets discovered.
To manually register a factory, simply pass an instance of your factory to the
#register(T) method. This can be useful when your factory cannot be
instantiated without arguments or in cases where automatic discovery does not give your factory
priority. Factories registered this way will be registered at the start of the factories list so
will have the first opportunity to indicate whether they support a requested path.
|Constructor and Description|
Constructs a registry for loading extension of a particular type.
|Modifier and Type||Method and Description|
Finds all the factories that support the given path.
Returns a read-only view of the available base factories.
Registers a new factory.
Resets the registry to its default state
Unregisters an existing factory.
factoryClass- the type of the extension factory
extensionPattern- the pattern used to select libraries to be loaded
conf- configuration of the extension
public void register(T factory)
Factories are registered at the start of the factories list so they can override the existing
automatically discovered factories. Generally if you use the
properly it should be unnecessary to call this, however since ServiceLoader discovery order
may be susceptible to class loader behavioral differences there may be rare cases when you
need to manually register the desired factory.
factory- factory to register
public void reset()
This clears the registry as it stands and rediscovers the available factories.
public void unregister(T factory)
factory- factory to unregister
Copyright © 2022. All Rights Reserved.