Class ServiceHelper

java.lang.Object
dev.langchain4j.spi.ServiceHelper

public class ServiceHelper extends Object
Utility wrapper around ServiceLoader.load().
  • Method Details

    • loadFactories

      public static <T> Collection<T> loadFactories(Class<T> clazz)
      Load all the services of a given type.
      Type Parameters:
      T - the type of service
      Parameters:
      clazz - the type of service
      Returns:
      the list of services, empty if none
    • loadFactories

      public static <T> Collection<T> loadFactories(Class<T> clazz, ClassLoader classLoader)
      Load all the services of a given type.

      Utility mechanism around ServiceLoader.load()

      • If classloader is null, will try ServiceLoader.load(clazz)
      • If classloader is not null, will try ServiceLoader.load(clazz, classloader)

      If the above return nothing, will fall back to ServiceLoader.load(clazz, $this class loader$)

      Type Parameters:
      T - the type of service
      Parameters:
      clazz - the type of service
      classLoader - the classloader to use, may be null
      Returns:
      the list of services, empty if none