Class MapServiceLoader<S>

java.lang.Object
org.miaixz.bus.core.lang.loader.spi.AbsServiceLoader<S>
org.miaixz.bus.core.lang.loader.spi.MapServiceLoader<S>
Type Parameters:
S - 服务类型
All Implemented Interfaces:
Iterable<S>, ServiceLoader<S>

public class MapServiceLoader<S> extends AbsServiceLoader<S>
键值对服务加载器,使用Properties加载并存储服务 服务文件默认位于"META-INF/bus/"下,文件名为服务接口类全名。 内容类似于:
     # 我是注释
     service1 = service.Service1
     service2 = service.Service2
 
通过调用getService(String)方法,传入等号前的名称,即可获取对应服务。
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • MapServiceLoader

      public MapServiceLoader(String pathPrefix, Class<S> serviceClass, ClassLoader classLoader, Charset charset)
      构造
      Parameters:
      pathPrefix - 路径前缀
      serviceClass - 服务名称
      classLoader - 自定义类加载器, null表示使用默认当前的类加载器
      charset - 编码,默认UTF-8
  • Method Details

    • of

      public static <S> MapServiceLoader<S> of(Class<S> serviceClass)
      构建KVServiceLoader
      Type Parameters:
      S - 服务类型
      Parameters:
      serviceClass - 服务名称
      Returns:
      KVServiceLoader
    • of

      public static <S> MapServiceLoader<S> of(Class<S> serviceClass, ClassLoader classLoader)
      构建KVServiceLoader
      Type Parameters:
      S - 服务类型
      Parameters:
      serviceClass - 服务名称
      classLoader - 自定义类加载器, null表示使用默认当前的类加载器
      Returns:
      KVServiceLoader
    • of

      public static <S> MapServiceLoader<S> of(String pathPrefix, Class<S> serviceClass, ClassLoader classLoader)
      构建KVServiceLoader
      Type Parameters:
      S - 服务类型
      Parameters:
      pathPrefix - 路径前缀
      serviceClass - 服务名称
      classLoader - 自定义类加载器, null表示使用默认当前的类加载器
      Returns:
      KVServiceLoader
    • load

      public void load()
      加载或重新加载全部服务
    • size

      public int size()
      Description copied from interface: ServiceLoader
      服务总数
      Returns:
      总数
    • getServiceNames

      public List<String> getServiceNames()
      Description copied from interface: ServiceLoader
      获取服务名称列表
      Returns:
      服务名称列表
    • getServiceClass

      public Class<S> getServiceClass(String serviceName)
      Description copied from interface: ServiceLoader
      获取指定服务的实现类
      Parameters:
      serviceName - 服务名称
      Returns:
      服务名称对应的实现类
    • getService

      public S getService(String serviceName)
      Description copied from interface: ServiceLoader
      获取指定名称对应的服务
      Parameters:
      serviceName - 服务名称
      Returns:
      服务对象
    • iterator

      public Iterator<S> iterator()