Class PluginRepository
- All Implemented Interfaces:
URLStreamHandlerFactory
The plugin repository is a registry of all plugins.
At system boot up a repository is built by parsing the manifest files of all plugins. Plugins that require other plugins which do not exist are not registered. For each plugin a plugin descriptor instance will be created. The descriptor represents all meta information about a plugin. So a plugin instance will be created later when it is required, this allow lazy plugin loading.
As protocol-plugins need to be registered with the JVM as well, this class
also acts as an URLStreamHandlerFactory that registers with
the JVM and supports all the new protocols as if they were native. Details of
how the JVM creates URLs can be seen in the API documentation for the
URL constructor.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateURLStreamHandler(String protocol) Invoked whenever aURLneeds to be instantiated.voidfinalize()Deprecated.static PluginRepositoryget(Configuration conf) Get a cached instance of thePluginRepositoryClass<?>getCachedClass(PluginDescriptor pDescriptor, String className) getExtensionPoint(String pXpId) Returns a extension point identified by a extension point id.Object[]getOrderedPlugins(Class<?> clazz, String xPointId, String orderProperty) Get ordered list of plugins.getPluginDescriptor(String pPluginId) Returns the descriptor of one plugin identified by a plugin id.Returns all registed plugin descriptors.getPluginInstance(PluginDescriptor pDescriptor) Returns an instance of a plugin.static voidLoads all necessary dependencies for a selected plugin, and then runs one of the classes' main() method.
-
Field Details
-
LOG
protected static final org.slf4j.Logger LOG
-
-
Constructor Details
-
PluginRepository
- Parameters:
conf- a populatedConfiguration- Throws:
RuntimeException- if a fatal runtime error is encountered
-
-
Method Details
-
get
Get a cached instance of thePluginRepository- Parameters:
conf- a populatedConfiguration- Returns:
- a cached instance of the plugin repository
-
getPluginDescriptors
Returns all registed plugin descriptors.- Returns:
- PluginDescriptor[]
-
getPluginDescriptor
Returns the descriptor of one plugin identified by a plugin id.- Parameters:
pPluginId- a pluginId for which the descriptor will be retrieved- Returns:
- PluginDescriptor
-
getExtensionPoint
Returns a extension point identified by a extension point id.- Parameters:
pXpId- an extension point id- Returns:
- a extentsion point
-
getPluginInstance
Returns an instance of a plugin. Plugin instances are cached. So a plugin exist only as one instance. This allow a central management of plugin's own resources.
After creating the plugin instance the startUp() method is invoked. The plugin use a own classloader that is used as well by all instance of extensions of the same plugin. This class loader use all exported libraries from the dependent plugins and all plugin libraries.
- Parameters:
pDescriptor- aPluginDescriptorfor which to retrieve aPlugininstance- Returns:
- a
Plugininstance - Throws:
PluginRuntimeException- if there is a fatal runtime plugin error
-
finalize
Deprecated.Attempts to shut down all activated plugins. -
getCachedClass
public Class<?> getCachedClass(PluginDescriptor pDescriptor, String className) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
getOrderedPlugins
Get ordered list of plugins. Filter and normalization plugins are applied in a configurable "pipeline" order, e.g., if one plugin depends on the output of another plugin. This method loads the plugins in the order defined by orderProperty. If orderProperty is empty or unset, all active plugins of the given interface and extension point are loaded.- Parameters:
clazz- interface class implemented by required pluginsxPointId- extension point id of required pluginsorderProperty- property name defining plugin order- Returns:
- array of plugin instances
-
main
Loads all necessary dependencies for a selected plugin, and then runs one of the classes' main() method.- Parameters:
args- plugin ID (needs to be activated in the configuration), and the class name. The rest of arguments is passed to the main method of the selected class.- Throws:
Exception- if there is an error running this Class
-
createURLStreamHandler
Invoked whenever a
This is done by several attempts:URLneeds to be instantiated. Tries to find a suitable extension and allows it to provide aURLStreamHandler.- Find a protocol plugin that implements the desired protocol. If found,
instantiate it so eventually the plugin can install a
URLStreamHandlerthrough a static hook. - If the plugin specifies a
URLStreamHandlerin itsplugin.xmlmanifest, return an instance of thisURLStreamHandler. Example:... <implementation id="org.apache.nutch.protocol.foo.Foo" class="org.apache.nutch.protocol.foo.Foo"> <parameter name="protocolName" value="foo"/> <parameter name="urlStreamHandler" value="org.apache.nutch.protocol.foo.Handler"/> </implementation> ... - If all else fails, return null. This will fallback to the JVM's method
of evaluating the system property
java.protocol.handler.pkgs.
- Specified by:
createURLStreamHandlerin interfaceURLStreamHandlerFactory- Returns:
- the URLStreamHandler found, or null.
- See Also:
- Find a protocol plugin that implements the desired protocol. If found,
instantiate it so eventually the plugin can install a
-