本文整理汇总了Java中java.util.ServiceLoader.loadInstalled方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceLoader.loadInstalled方法的具体用法?Java ServiceLoader.loadInstalled怎么用?Java ServiceLoader.loadInstalled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ServiceLoader
的用法示例。
在下文中一共展示了ServiceLoader.loadInstalled方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerInstalledProviders
import java.util.ServiceLoader; //导入方法依赖的package包/类
private void registerInstalledProviders() {
/*
We need to load installed providers from the
system classpath (typically the <code>lib/ext</code>
directory in in the Java installation directory)
in the privileged mode in order to
be able read corresponding jar files even if
file read capability is restricted (like the
applet context case).
*/
PrivilegedAction doRegistration =
new PrivilegedAction() {
public Object run() {
Iterator categories = getCategories();
while (categories.hasNext()) {
Class<IIOServiceProvider> c = (Class)categories.next();
for (IIOServiceProvider p : ServiceLoader.loadInstalled(c)) {
registerServiceProvider(p);
}
}
return this;
}
};
AccessController.doPrivileged(doRegistration);
}
示例2: registerInstalledProviders
import java.util.ServiceLoader; //导入方法依赖的package包/类
private void registerInstalledProviders() {
/*
We need to load installed providers
in the privileged mode in order to
be able read corresponding jar files even if
file read capability is restricted (like the
applet context case).
*/
PrivilegedAction<Object> doRegistration =
new PrivilegedAction<Object>() {
public Object run() {
Iterator<Class<?>> categories = getCategories();
while (categories.hasNext()) {
@SuppressWarnings("unchecked")
Class<IIOServiceProvider> c = (Class<IIOServiceProvider>)categories.next();
for (IIOServiceProvider p : ServiceLoader.loadInstalled(c)) {
registerServiceProvider(p);
}
}
return this;
}
};
AccessController.doPrivileged(doRegistration);
}
示例3: getServiceLoader
import java.util.ServiceLoader; //导入方法依赖的package包/类
private ServiceLoader<ScriptEngineFactory> getServiceLoader(final ClassLoader loader) {
if (loader != null) {
return ServiceLoader.load(ScriptEngineFactory.class, loader);
} else {
return ServiceLoader.loadInstalled(ScriptEngineFactory.class);
}
}
示例4: loadBundleOf
import java.util.ServiceLoader; //导入方法依赖的package包/类
private static ResourceBundle loadBundleOf(String baseName,
Locale targetLocale,
Strategy strategy) {
Objects.requireNonNull(baseName);
Objects.requireNonNull(targetLocale);
Objects.requireNonNull(strategy);
CacheKey cacheKey = new CacheKey(baseName, targetLocale);
ResourceBundle bundle = null;
// Quick lookup of the cache.
BundleReference bundleRef = cacheList.get(cacheKey);
if (bundleRef != null) {
bundle = bundleRef.get();
}
// If this bundle and all of its parents are valid,
// then return this bundle.
if (isValidBundle(bundle)) {
return bundle;
}
// Get the providers for loading the "leaf" bundle (i.e., bundle for
// targetLocale). If no providers are required for the bundle,
// none of its parents will require providers.
Class<? extends ResourceBundleProvider> type
= strategy.getResourceBundleProviderType(baseName, targetLocale);
if (type != null) {
@SuppressWarnings("unchecked")
ServiceLoader<ResourceBundleProvider> providers
= (ServiceLoader<ResourceBundleProvider>) ServiceLoader.loadInstalled(type);
cacheKey.setProviders(providers);
}
List<Locale> candidateLocales = strategy.getCandidateLocales(baseName, targetLocale);
bundle = findBundleOf(cacheKey, strategy, baseName, candidateLocales, 0);
if (bundle == null) {
throwMissingResourceException(baseName, targetLocale, cacheKey.getCause());
}
return bundle;
}
示例5: testLoadNull5
import java.util.ServiceLoader; //导入方法依赖的package包/类
@Test(expectedExceptions = { NullPointerException.class })
public void testLoadNull5() {
ServiceLoader.loadInstalled(null);
}
示例6: getConnectorAsService
import java.util.ServiceLoader; //导入方法依赖的package包/类
/**
* Creates a connector from a provider loaded from the ServiceLoader.
* <p>
* The pair (P,C) will be either one of: <br>
* a. (JMXConnectorProvider, JMXConnector) or <br>
* b. (JMXConnectorServerProvider, JMXConnectorServer)
*
* @param providerClass The service type for which an implementation
* should be looked up from the {@code ServiceLoader}. This will
* be either {@code JMXConnectorProvider.class} or
* {@code JMXConnectorServerProvider.class}
*
* @param loader The ClassLoader to use when looking up an implementation
* of the service. If null, then only installed services will be
* considered.
*
* @param url The JMXServiceURL of the connector for which a provider is
* requested.
*
* @param filter A filter used to exclude or return provider
* implementations. Typically the filter will either exclude
* system services (system default implementations) or only
* retain those.
* This can allow to first look for custom implementations (e.g.
* deployed on the CLASSPATH with META-INF/services) and
* then only default to system implementations.
*
* @param factory A functional factory that can attempt to create an
* instance of connector {@code C} from a provider {@code P}.
* Typically, this is a simple wrapper over {@code
* JMXConnectorProvider::newJMXConnector} or {@code
* JMXConnectorProviderServer::newJMXConnectorServer}.
*
* @throws IOException if {@code C} could not be instantiated, and
* at least one provider {@code P} threw an exception that wasn't a
* {@code MalformedURLException} or a {@code JMProviderException}.
*
* @throws JMXProviderException if a provider {@code P} for the protocol in
* <code>url</code> was found, but couldn't create the connector
* {@code C} for some reason.
*
* @return an instance of {@code C} if a provider {@code P} was found from
* which one could be instantiated, {@code null} otherwise.
*/
static <P,C> C getConnectorAsService(Class<P> providerClass,
ClassLoader loader,
JMXServiceURL url,
Predicate<Provider<?>> filter,
ConnectorFactory<P,C> factory)
throws IOException {
// sanity check
if (JMXConnectorProvider.class != providerClass
&& JMXConnectorServerProvider.class != providerClass) {
// should never happen
throw new InternalError("Unsupported service interface: "
+ providerClass.getName());
}
ServiceLoader<P> serviceLoader = loader == null
? ServiceLoader.loadInstalled(providerClass)
: ServiceLoader.load(providerClass, loader);
Stream<Provider<P>> stream = serviceLoader.stream().filter(filter);
ProviderFinder<P,C> finder = new ProviderFinder<>(factory, url);
try {
stream.filter(finder).findFirst();
return finder.get();
} catch (UncheckedIOException e) {
if (e.getCause() instanceof JMXProviderException) {
throw (JMXProviderException) e.getCause();
} else {
throw e;
}
}
}
示例7: run
import java.util.ServiceLoader; //导入方法依赖的package包/类
void run() { ServiceLoader.loadInstalled(null); }