Class PluginRepository

java.lang.Object
nz.org.riskscape.engine.plugin.PluginRepository

public class PluginRepository extends Object

The PluginRepository is a registry of plugins.

Engine building code can use a PluginRepository to assemble a set of plugins to use to populate an engine. A PluginRepository can in theory be used to assemble multiple engine instances. While this isn't very interesting for a CLI, where engine construction is per invocation, this might come in use with a webapp or API.

Each plugin is given its own classloader, PluginClassLoader, which isolates it from other plugins and from the Engine itself.

See comments on addPath(File) for notes on Plugin structure.

Derived from the Nutch project's plugin system

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final PluginRepository
     
  • Method Summary

    Modifier and Type
    Method
    Description
    List<nz.org.riskscape.engine.plugin.Plugin>
    activateAll(Consumer<nz.org.riskscape.engine.plugin.Plugin> visitor)
     
    protected nz.org.riskscape.engine.plugin.Plugin
    activatePlugin(nz.org.riskscape.engine.plugin.PluginDescriptor descriptor, Consumer<nz.org.riskscape.engine.plugin.Plugin> visitor)
     
    void
    addActivated(nz.org.riskscape.engine.plugin.Plugin plugin)
    Register an already 'activated' plugin with this repository.
    void
    addPath(File plugin)
    Constructs a PluginDescriptor from either a single jar file or a directory containing jars and adds it to this PluginRepository.
    nz.org.riskscape.engine.plugin.ExtensionPoints
    collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints)
    Collects all the ExtensionPoints and PluginFeatures advertised by activated plugins and returns them in a new ExtensionPoints object.
    static void
    collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints, List<nz.org.riskscape.engine.plugin.Plugin> plugins)
    Collect all the ExtensionPoints and PluginFeatures from the given list of plugins and add them to the given ExtensionPoints.
    static void
    collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints, nz.org.riskscape.engine.plugin.Plugin... plugins)
    Collect all the ExtensionPoints and PluginFeatures from the given plugins and add them to the given ExtensionPoints.
    void
     
    List<nz.org.riskscape.engine.plugin.Plugin>
     
    <T extends nz.org.riskscape.engine.plugin.Plugin>
    Optional<T>
    getActivatedPlugin(Class<T> pluginClass)
     
    Optional<nz.org.riskscape.engine.plugin.Plugin>
     
    Optional<nz.org.riskscape.engine.plugin.PluginDescriptor>
    getPluginById(String dependencyId)
     
    void
    register(nz.org.riskscape.engine.plugin.PluginDescriptor descriptor)
    Register a plugin, but without activating it.
    void
    scanDirectory(Path directory)
     

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • collectFeatures

      public static void collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints, List<nz.org.riskscape.engine.plugin.Plugin> plugins)

      Collect all the ExtensionPoints and PluginFeatures from the given list of plugins and add them to the given ExtensionPoints.

    • collectFeatures

      public static void collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints, nz.org.riskscape.engine.plugin.Plugin... plugins)

      Collect all the ExtensionPoints and PluginFeatures from the given plugins and add them to the given ExtensionPoints.

    • scanDirectory

      public void scanDirectory(Path directory)
    • addActivated

      public void addActivated(nz.org.riskscape.engine.plugin.Plugin plugin)

      Register an already 'activated' plugin with this repository. This allows a plugin to be used that has been constructed outside of the usual code-loading mechanism

    • register

      public void register(nz.org.riskscape.engine.plugin.PluginDescriptor descriptor)

      Register a plugin, but without activating it. It will get activated in due course by the activateAll method instead.

    • addPath

      public void addPath(File plugin)

      Constructs a PluginDescriptor from either a single jar file or a directory containing jars and adds it to this PluginRepository.

      If plugin points to a directory, that directory must contain at least a jar named plugin.jar which must contain a manifest that the PluginDescriptor can read. All other jars will be loaded from that directory, with plugin.jar always being loaded first.

      If plugin points to a jar file, then this is loaded by itself like plugin.jar from the directory example before

      Parameters:
      plugin - either a jar file or a directory
    • activateAll

      public List<nz.org.riskscape.engine.plugin.Plugin> activateAll(Consumer<nz.org.riskscape.engine.plugin.Plugin> visitor)
    • collectFeatures

      public nz.org.riskscape.engine.plugin.ExtensionPoints collectFeatures(nz.org.riskscape.engine.plugin.ExtensionPoints extensionPoints)

      Collects all the ExtensionPoints and PluginFeatures advertised by activated plugins and returns them in a new ExtensionPoints object.

    • activatePlugin

      protected nz.org.riskscape.engine.plugin.Plugin activatePlugin(nz.org.riskscape.engine.plugin.PluginDescriptor descriptor, Consumer<nz.org.riskscape.engine.plugin.Plugin> visitor)
    • getPluginById

      public Optional<nz.org.riskscape.engine.plugin.PluginDescriptor> getPluginById(String dependencyId)
      Returns:
      a PluginDescriptor from the list of registered plugins with the given dependencyId, or empty if there is no plugin registered with that id
    • finalize

      public void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • getActivatedPlugin

      public Optional<nz.org.riskscape.engine.plugin.Plugin> getActivatedPlugin(String pluginId)
    • getActivatedPlugin

      public <T extends nz.org.riskscape.engine.plugin.Plugin> Optional<T> getActivatedPlugin(Class<T> pluginClass)
    • getActivated

      public List<nz.org.riskscape.engine.plugin.Plugin> getActivated()
      Returns:
      a set of all the activated plugins in this repository