Class NamedSPILoader<S extends NamedSPILoader.NamedSPI>

  • All Implemented Interfaces:
    java.lang.Iterable<S>

    public final class NamedSPILoader<S extends NamedSPILoader.NamedSPI>
    extends java.lang.Object
    implements java.lang.Iterable<S>
    Helper class for loading named SPIs from classpath (e.g. Codec, PostingsFormat).
    • Constructor Summary

      Constructors 
      Constructor Description
      NamedSPILoader​(java.lang.Class<S> clazz)  
      NamedSPILoader​(java.lang.Class<S> clazz, java.lang.ClassLoader classloader)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<java.lang.String> availableServices()  
      static void checkServiceName​(java.lang.String name)
      Validates that a service name meets the requirements of NamedSPILoader.NamedSPI
      java.util.Iterator<S> iterator()  
      S lookup​(java.lang.String name)  
      void reload​(java.lang.ClassLoader classloader)
      Reloads the internal SPI list from the given ClassLoader.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • NamedSPILoader

        public NamedSPILoader​(java.lang.Class<S> clazz)
      • NamedSPILoader

        public NamedSPILoader​(java.lang.Class<S> clazz,
                              java.lang.ClassLoader classloader)
    • Method Detail

      • reload

        public void reload​(java.lang.ClassLoader classloader)
        Reloads the internal SPI list from the given ClassLoader. Changes to the service list are visible after the method ends, all iterators (iterator(),...) stay consistent.

        NOTE: Only new service providers are added, existing ones are never removed or replaced.

        This method is expensive and should only be called for discovery of new service providers on the given classpath/classloader!

      • checkServiceName

        public static void checkServiceName​(java.lang.String name)
        Validates that a service name meets the requirements of NamedSPILoader.NamedSPI
      • lookup

        public S lookup​(java.lang.String name)
      • availableServices

        public java.util.Set<java.lang.String> availableServices()
      • iterator

        public java.util.Iterator<S> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<S extends NamedSPILoader.NamedSPI>