本文整理匯總了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); }