本文整理汇总了Java中sun.misc.Service类的典型用法代码示例。如果您正苦于以下问题:Java Service类的具体用法?Java Service怎么用?Java Service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Service类属于sun.misc包,在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import sun.misc.Service; //导入依赖的package包/类
public Object run() {
Iterator itr
= Service.providers(NameServiceDescriptor.class);
while (itr.hasNext()) {
NameServiceDescriptor nsd
= (NameServiceDescriptor)itr.next();
if (providerName.
equalsIgnoreCase(nsd.getType()+","
+nsd.getProviderName())) {
try {
nameService = nsd.createNameService();
break;
} catch (Exception e) {
e.printStackTrace();
System.err.println(
"Cannot create name service:"
+providerName+": " + e);
}
}
} /* while */
return null;
}
示例2: loadProviderAsService
import sun.misc.Service; //导入依赖的package包/类
private static boolean loadProviderAsService() {
Iterator i = Service.providers(SelectorProvider.class,
ClassLoader.getSystemClassLoader());
for (;;) {
try {
if (!i.hasNext())
return false;
provider = (SelectorProvider)i.next();
return true;
} catch (ServiceConfigurationError sce) {
if (sce.getCause() instanceof SecurityException) {
// Ignore the security exception, try the next provider
continue;
}
throw sce;
}
}
}
示例3: webstartSetup
import sun.misc.Service; //导入依赖的package包/类
public static void webstartSetup() {
logger.warning("Running from Java Web Start. Performing setup.");
// setup a URL stream handler for the Wonderland protocols. This
// works around the fact that URL will only find handlers
// loaded in the system classloader, and in webstart the
// handlers we need (wonderland.protocol.*) are in the jnlp classloader.
//
//
// Note if we return null here, it will go on to try the normal
// mechanisms defined in URL
URL.setURLStreamHandlerFactory(new WonderlandURLStreamHandlerFactory());
// set our own security manager
logger.info("Setting security manager");
System.setSecurityManager(new JnlpSecurityManager());
// discover listeners using service loader mechanism
Iterator<WebstartStartupListener> it =
Service.providers(WebstartStartupListener.class);
while (it.hasNext()) {
WebstartStartupListener wsl = it.next();
wsl.onStartup();
}
}
示例4: run
import sun.misc.Service; //导入依赖的package包/类
public NameService run() {
Iterator itr = Service.providers(NameServiceDescriptor.class);
while (itr.hasNext()) {
NameServiceDescriptor nsd
= (NameServiceDescriptor)itr.next();
if (providerName.
equalsIgnoreCase(nsd.getType()+","
+nsd.getProviderName())) {
try {
return nsd.createNameService();
} catch (Exception e) {
e.printStackTrace();
System.err.println(
"Cannot create name service:"
+providerName+": " + e);
}
}
}
return null;
}
示例5: loadProviderAsService
import sun.misc.Service; //导入依赖的package包/类
private static boolean loadProviderAsService() {
Iterator i = Service.providers(HttpServerProvider.class,
ClassLoader.getSystemClassLoader());
for (;;) {
try {
if (!i.hasNext())
return false;
provider = (HttpServerProvider)i.next();
return true;
} catch (ServiceConfigurationError sce) {
if (sce.getCause() instanceof SecurityException) {
// Ignore the security exception, try the next provider
continue;
}
throw sce;
}
}
}
示例6: main
import sun.misc.Service; //导入依赖的package包/类
public static void main() {
// in jdk.unsupported
Class<?> caller = Reflection.getCallerClass(2);
// removed
JPEGCodec r = new JPEGCodec();
// removed
SoftCache s = new SoftCache();
// removed
Service.providers(S.class);
}
示例7: run
import sun.misc.Service; //导入依赖的package包/类
public Object run() {
// uncomment the followin line before mustang integration
// Service s = Service.lookup(java.sql.Driver.class);
// ps = s.iterator();
ps = Service.providers(java.sql.Driver.class);
/* Load these drivers, so that they can be instantiated.
* It may be the case that the driver class may not be there
* i.e. there may be a packaged driver with the service class
* as implementation of java.sql.Driver but the actual class
* may be missing. In that case a sun.misc.ServiceConfigurationError
* will be thrown at runtime by the VM trying to locate
* and load the service.
*
* Adding a try catch block to catch those runtime errors
* if driver not available in classpath but it's
* packaged as service and that service is there in classpath.
*/
try {
while (ps.hasNext()) {
ps.next();
} // end while
} catch(Throwable t) {
// Do nothing
}
return null;
}
示例8: factory1
import sun.misc.Service; //导入依赖的package包/类
private static PreferencesFactory factory1() {
// 2. Try service provider interface
Iterator i = Service.providers(PreferencesFactory.class,
ClassLoader.getSystemClassLoader());
// choose first provider instance
while (i.hasNext()) {
try {
return (PreferencesFactory) i.next();
} catch (ServiceConfigurationError sce) {
if (sce.getCause() instanceof SecurityException) {
// Ignore the security exception, try the next provider
continue;
}
throw sce;
}
}
// 3. Use platform-specific system-wide default
String platformFactory =
System.getProperty("os.name").startsWith("Windows")
? "java.util.prefs.WindowsPreferencesFactory"
: "java.util.prefs.FileSystemPreferencesFactory";
try {
return (PreferencesFactory)
Class.forName(platformFactory, false, null).newInstance();
} catch (Exception e) {
InternalError error = new InternalError(
"Can't instantiate platform default Preferences factory "
+ platformFactory);
error.initCause(e);
throw error;
}
}
示例9: getClasses
import sun.misc.Service; //导入依赖的package包/类
/**
* Find and return all the classes that implement the ModuleDeployerSPI
* inteface
*
* @return
*/
private Class[] getClasses() {
Iterator<ModuleDeployerSPI> it = Service.providers(ModuleDeployerSPI.class);
// use a linked hash set to preserve a static ordering
Collection<Class> names = new LinkedHashSet<Class>();
while (it.hasNext() == true) {
names.add(it.next().getClass());
}
return names.toArray(new Class[]{} );
}
示例10: getAll
import sun.misc.Service; //导入依赖的package包/类
/**
* Get instances of all classes that implement the given interface,
* defined either by service provider or by annoation.
* @param annot the annotation to search for
* @param clazz the class of the return type
* @return an iterator of instantiated instances of the given type
*/
public <T> Iterator<T> getAll(Class<? extends Annotation> annot,
Class<T> clazz)
{
// get the iterator for service providers
final Iterator<T> providers = Service.providers(clazz, this);
// get the iterator for annotations
final Iterator<T> annots = getInstances(annot, clazz);
// return a combined iterator
return new Iterator<T>() {
private boolean p = true;
public boolean hasNext() {
if (p && providers.hasNext()) {
return true;
} else {
p = false;
return annots.hasNext();
}
}
public T next() {
if (p) {
return providers.next();
} else {
return annots.next();
}
}
public void remove() {
throw new UnsupportedOperationException("Not supported.");
}
};
}
示例11: getProviders
import sun.misc.Service; //导入依赖的package包/类
static List getProviders(final Class providerClass) {
List p = new ArrayList();
// Service.providers(Class) just creates "lazy" iterator instance,
// so it doesn't require do be called from privileged section
final Iterator ps = Service.providers(providerClass);
// the iterator's hasNext() method looks through classpath for
// the provider class names, so it requires read permissions
PrivilegedAction<Boolean> hasNextAction = new PrivilegedAction<Boolean>() {
public Boolean run() {
return ps.hasNext();
}
};
while (AccessController.doPrivileged(hasNextAction)) {
try {
// the iterator's next() method creates instances of the
// providers and it should be called in the current security
// context
Object provider = ps.next();
if (providerClass.isInstance(provider)) {
// $$mp 2003-08-22
// Always adding at the beginning reverses the
// order of the providers. So we no longer have
// to do this in AudioSystem and MidiSystem.
p.add(0, provider);
}
} catch (Throwable t) {
//$$fb 2002-11-07: do not fail on SPI not found
if (Printer.err) t.printStackTrace();
}
}
return p;
}
示例12: getProviders
import sun.misc.Service; //导入依赖的package包/类
static synchronized List getProviders(final Class providerClass) {
List p = new ArrayList();
// Service.providers(Class) just creates "lazy" iterator instance,
// so it doesn't require do be called from privileged section
final Iterator ps = Service.providers(providerClass);
// the iterator's hasNext() method looks through classpath for
// the provider class names, so it requires read permissions
PrivilegedAction<Boolean> hasNextAction = new PrivilegedAction<Boolean>() {
public Boolean run() {
return ps.hasNext();
}
};
while (AccessController.doPrivileged(hasNextAction)) {
try {
// the iterator's next() method creates instances of the
// providers and it should be called in the current security
// context
Object provider = ps.next();
if (providerClass.isInstance(provider)) {
// $$mp 2003-08-22
// Always adding at the beginning reverses the
// order of the providers. So we no longer have
// to do this in AudioSystem and MidiSystem.
p.add(0, provider);
}
} catch (Throwable t) {
//$$fb 2002-11-07: do not fail on SPI not found
if (Printer.err) t.printStackTrace();
}
}
return p;
}
示例13: check_federated_provider_service_is_published
import sun.misc.Service; //导入依赖的package包/类
@Test
public void check_federated_provider_service_is_published() {
final Iterator providers = Service.providers(IntegralIntermediateFederatedProvider.class);
boolean ok = providers.hasNext();
assertThat(ok).isTrue();
Object svc = providers.next();
assertThat(svc).isInstanceOf(IntegralIntermediateFederatedProvider.class);
assertThat(svc).isInstanceOf(JdbcIntermediateFederatedProvider.class);
}
示例14: check_unknown_database_provider_service_is_published
import sun.misc.Service; //导入依赖的package包/类
@Test
public void check_unknown_database_provider_service_is_published() {
final Iterator providers = Service.providers(IntegralIntermediateRdbmsProvider.class);
boolean ok = providers.hasNext();
assertThat(ok).isTrue();
Object svc = providers.next();
assertThat(svc).isInstanceOf(IntegralIntermediateRdbmsProvider.class);
assertThat(svc).isInstanceOf(JdbcIntermediateRdbmsProvider.class);
}
示例15: providers
import sun.misc.Service; //导入依赖的package包/类
private static Iterator providers() {
return new Iterator() {
Class c = java.nio.charset.spi.CharsetProvider.class;
ClassLoader cl = ClassLoader.getSystemClassLoader();
Iterator i = Service.providers(c, cl);
Object next = null;
private boolean getNext() {
while (next == null) {
try {
if (!i.hasNext())
return false;
next = i.next();
} catch (ServiceConfigurationError sce) {
if (sce.getCause() instanceof SecurityException) {
// Ignore security exceptions
continue;
}
throw sce;
}
}
return true;
}
public boolean hasNext() {
return getNext();
}
public Object next() {
if (!getNext())
throw new NoSuchElementException();
Object n = next;
next = null;
return n;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}