Class SpiHelper


  • public final class SpiHelper
    extends java.lang.Object
    This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
    • Constructor Detail

    • Method Detail

      • create

        public static SpiHelper create​(java.lang.ClassLoader classLoader)
        Create a SpiHelper which loads SPIs using the classLoader.
      • serviceComponentLoader

        public static ComponentLoader serviceComponentLoader​(java.lang.ClassLoader classLoader)
        Create a ComponentLoader which loads using the classLoader.
      • loadConfigurable

        public <T,​S> NamedSpiManager<T> loadConfigurable​(java.lang.Class<S> spiClass,
                                                               java.util.function.Function<S,​java.lang.String> getName,
                                                               java.util.function.BiFunction<S,​ConfigProperties,​T> getConfigurable,
                                                               ConfigProperties config)
        Load implementations of an SPI which are configurable (i.e. they accept ConfigProperties.
        Type Parameters:
        T - the configurable type
        S - the SPI type
        Parameters:
        spiClass - the SPI class
        getName - function returning the name of an SPI implementation
        getConfigurable - function returning a configured instance
        config - the configuration to pass to invocations of #getConfigurable
        Returns:
        a NamedSpiManager used to access configured instances of the SPI by name
      • loadOrdered

        public <T extends Ordered> java.util.List<T> loadOrdered​(java.lang.Class<T> spiClass)
        Load implementations of an ordered SPI (i.e. implements Ordered).
        Type Parameters:
        T - the SPI type
        Parameters:
        spiClass - the SPI class
        Returns:
        list of SPI implementations, in order
      • load

        public <T> java.util.List<T> load​(java.lang.Class<T> spiClass)
        Load implementations of an SPI.
        Type Parameters:
        T - the SPI type
        Parameters:
        spiClass - the SPI class
        Returns:
        list of SPI implementations
      • maybeAddListener

        private void maybeAddListener​(java.lang.Object object)