java.util.ServiceLoader.loadInstalled()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中java.util.ServiceLoader.loadInstalled()方法的一些代码示例,展示了ServiceLoader.loadInstalled()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServiceLoader.loadInstalled()方法的具体详情如下:
包路径:java.util.ServiceLoader
类名称:ServiceLoader
方法名:loadInstalled

ServiceLoader.loadInstalled介绍

[英]Constructs a service loader, using the extension class loader.
[中]使用扩展类加载器构造服务加载器。

代码示例

代码示例来源:origin: apache/geode

public ProviderAgent findProviderAgent() {
 ServiceLoader<ProviderAgent> serviceLoaderFromExt =
   ServiceLoader.loadInstalled(ProviderAgent.class);
 if (serviceLoaderFromExt.iterator().hasNext()) {
  ProviderAgent providerAgent = serviceLoaderFromExt.iterator().next();
  LOGGER.info("Using {} from Extension ClassLoader for service {}",
    providerAgent.getClass().getName(), ProviderAgent.class.getName());
  return providerAgent;
 }
 ServiceLoader<ProviderAgent> serviceLoaderFromTccl = ServiceLoader.load(ProviderAgent.class);
 if (serviceLoaderFromTccl.iterator().hasNext()) {
  ProviderAgent providerAgent = serviceLoaderFromTccl.iterator().next();
  LOGGER.info("Using {} from Thread Context ClassLoader for service {}",
    providerAgent.getClass().getName(), ProviderAgent.class.getName());
  return providerAgent;
 }
 ServiceLoader<ProviderAgent> serviceLoaderFromSys =
   ServiceLoader.load(ProviderAgent.class, null);
 if (serviceLoaderFromSys.iterator().hasNext()) {
  ProviderAgent providerAgent = serviceLoaderFromSys.iterator().next();
  LOGGER.info("Using {} from System ClassLoader for service {}",
    providerAgent.getClass().getName(), ProviderAgent.class.getName());
  return providerAgent;
 }
 return createProviderAgent();
}

代码示例来源:origin: apache/tinkerpop

private ServiceLoader<GremlinScriptEngineFactory> getServiceLoader(final ClassLoader loader) {
  if (loader != null) {
    return ServiceLoader.load(GremlinScriptEngineFactory.class, loader);
  } else {
    return ServiceLoader.loadInstalled(GremlinScriptEngineFactory.class);
  }
}

代码示例来源:origin: com.netflix.governator/governator

@Override
  public ServiceLoader<S> call() throws Exception {
    return ServiceLoader.loadInstalled(type);
  }
};

代码示例来源:origin: com.netflix.governator/governator-core

@Override
  public ServiceLoader<S> call() throws Exception {
    return ServiceLoader.loadInstalled(type);
  }
};

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

private ServiceLoader<GremlinScriptEngineFactory> getServiceLoader(final ClassLoader loader) {
  if (loader != null) {
    return ServiceLoader.load(GremlinScriptEngineFactory.class, loader);
  } else {
    return ServiceLoader.loadInstalled(GremlinScriptEngineFactory.class);
  }
}

代码示例来源:origin: io.sarl.lang/io.sarl.lang.core

/** Replies all the installed SRE into the class path.
 *
 * @param onlyInstalledInJRE indicates if the services will be considered only into the libraries that are
 *     installed into the JRE. If {@code true}, only the libraries into the JRE will be considered and
 *     the application libraries will be ignored. If {@code false}, the application libraries will be
 *     considered as well.
 * @return the installed SRE.
 */
@Pure
public static ServiceLoader<SREBootstrap> getServiceLoader(boolean onlyInstalledInJRE) {
  synchronized (SRE.class) {
    ServiceLoader<SREBootstrap> sl = loader == null ? null : loader.get();
    if (sl == null) {
      if (onlyInstalledInJRE) {
        sl = ServiceLoader.loadInstalled(SREBootstrap.class);
      } else {
        sl = ServiceLoader.load(SREBootstrap.class);
      }
      loader = new SoftReference<>(sl);
    }
    return sl;
  }
}

代码示例来源:origin: pentaho/pentaho-hadoop-shims

/**
  * Creates a new service loader for the given service type, using the extension class loader.
  * <p/>
  * <p> This convenience method simply locates the extension class loader, call it <tt><i>extClassLoader</i></tt>, and
  * then returns
  * <p/>
  * <blockquote><pre>
  * OverloadedServiceLoader.load(<i>service</i>, <i>extClassLoader</i>)</pre></blockquote>
  * <p/>
  * <p> If the extension class loader cannot be found then the system class loader is used; if there is no system class
  * loader then the bootstrap class loader is used.
  * <p/>
  * <p> This method is intended for use when only installed providers are desired.  The resulting service will only
  * find and load providers that have been installed into the current Java virtual machine; providers on the
  * application's class path will be ignored.
  *
  * @param service The interface or abstract class representing the service
  * @return A new service loader
  */
public static <S> OverloadedServiceLoader<S> loadInstalled( Class<S> service ) {
 return new OverloadedServiceLoader<>( ServiceLoader.loadInstalled( service ) );
}

代码示例来源:origin: org.ceylon-lang/ceylon.language

ServiceLoader<Service> extensionServices = ServiceLoader.loadInstalled(klass);
ceylon.language.Iterable<? extends Service,? extends Object> services = new It(moduleServices).<Service,Object>chain($reified$Service, Null.$TypeDescriptor$, new It(extensionServices));

相关文章