Class PluginComponentLoader

java.lang.Object
org.apache.tika.plugins.PluginComponentLoader

public class PluginComponentLoader extends Object
  • Constructor Details

    • PluginComponentLoader

      public PluginComponentLoader()
  • Method Details

    • buildExtension

      public static <T extends TikaExtension> T buildExtension(TikaExtensionFactory<T> factory, ExtensionConfig config) throws TikaConfigException, IOException
      Builds an extension with the thread-context classloader set to the classloader of the plugin that supplied the factory.

      Client libraries a plugin bundles (Kafka, the AWS SDK, ZooKeeper) resolve classes named in their own configuration off the thread-context classloader and then cast the result to an interface resolved from their own classloader. Left at the host's classloader, that lookup either misses the plugin's lib/ entirely or - on a host that happens to carry the same library - finds a second copy of the class and the cast fails. Everything a plugin constructs must therefore see the plugin's classloader; pf4j does not set it.

      Threads the library starts during construction inherit it, which is what keeps its own background threads resolving against the plugin. Factories that are not plugin-supplied are invoked without touching the context classloader.

      Throws:
      TikaConfigException
      IOException
    • loadSingleton

      public static <T extends TikaExtension> Optional<T> loadSingleton(org.pf4j.PluginManager pluginManager, Class<? extends TikaExtensionFactory<T>> factoryClass, com.fasterxml.jackson.databind.JsonNode configNode) throws TikaConfigException, IOException
      Load a singleton component from config.

      JSON structure: { "typeName": { config } }

      Returns:
      Optional containing the instance, or empty if configNode is null/empty
      Throws:
      TikaConfigException
      IOException
    • loadInstances

      public static <T extends TikaExtension> Map<String,T> loadInstances(org.pf4j.PluginManager pluginManager, Class<? extends TikaExtensionFactory<T>> factoryClass, com.fasterxml.jackson.databind.JsonNode configNode) throws TikaConfigException, IOException
      Load multiple named instances from config, grouped by type.

      JSON structure:

       {
         "typeName": {
           "instanceId1": { config },
           "instanceId2": { config }
         },
         "typeName2": {
           "instanceId3": { config }
         }
       }
       

      Throws:
      TikaConfigException
      IOException
    • loadUnnamedInstances

      public static <T extends TikaExtension> List<T> loadUnnamedInstances(org.pf4j.PluginManager pluginManager, Class<? extends TikaExtensionFactory<T>> factoryClass, com.fasterxml.jackson.databind.JsonNode configNode) throws TikaConfigException, IOException
      Load multiple unnamed instances from config, keyed by type name.

      JSON structure: { "typeName": { config }, "typeName2": { config2 }, ... }

      Use this for composite components like reporters where each type appears once and instances don't need individual names.

      Returns:
      List of instances in config order, empty list if configNode is null/empty
      Throws:
      TikaConfigException
      IOException