• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Service类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中sun.misc.Service的典型用法代码示例。如果您正苦于以下问题:Java Service类的具体用法?Java Service怎么用?Java Service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Service类属于sun.misc包,在下文中一共展示了Service类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:23,代码来源:InetAddress.java


示例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;
    }
}
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:19,代码来源:SelectorProvider.java


示例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();
    }
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:26,代码来源:Webstart.java


示例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;
}
 
开发者ID:ZhaoX,项目名称:jdk-1.7-annotated,代码行数:22,代码来源:InetAddress.java


示例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;
        }
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:19,代码来源:HttpServerProvider.java


示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Main.java


示例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;
    }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:31,代码来源:DriverManager.java


示例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;
}
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:34,代码来源:Preferences.java


示例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[]{} );
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:18,代码来源:DeployManager.java


示例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.");
        }
    };
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:43,代码来源:ScannedClassLoader.java


示例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;
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:35,代码来源:JSSecurityManager.java


示例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;
}
 
开发者ID:greghaskins,项目名称:openjdk-jdk7u-jdk,代码行数:35,代码来源:JSSecurityManager.java


示例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);
}
 
开发者ID:JetBrains,项目名称:dekaf,代码行数:13,代码来源:JdbcJarProvidersTest.java


示例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);
}
 
开发者ID:JetBrains,项目名称:dekaf,代码行数:13,代码来源:JdbcJarProvidersTest.java


示例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();
	}

    };
   }
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:44,代码来源:Charset.java


示例16: CellBoundsViewer

import sun.misc.Service; //导入依赖的package包/类
/** Creates new form CellBoundsViewer */
public CellBoundsViewer(String[] args) {
    // load properties from file
    if (args.length == 1) {
        props = loadProperties(args[0]);
    } else {
        props = loadProperties(null);
    }
   
    String serverName = props.getProperty(SERVER_NAME_PROP,
                                          SERVER_NAME_DEFAULT);
    String serverPort = props.getProperty(SERVER_PORT_PROP,
                                          SERVER_PORT_DEFAULT);
    String userName   = props.getProperty(USER_NAME_PROP,
                                          USER_NAME_DEFAULT);
    WonderlandConfigUtil.setUsername(userName);
    
    initComponents();
    
    final BoundsPanel boundsPanel = new BoundsPanel();
    centerPanel.add(boundsPanel, BorderLayout.CENTER);
    this.setSize(640,480);
    
    long userNum = System.currentTimeMillis();
    
    WonderlandServerInfo server = new WonderlandServerInfo(serverName,
                                              Integer.parseInt(serverPort));
    
    LoginParameters loginParams = new LoginParameters(userName, 
                                                      "test".toCharArray());
    
    // setup a classloader with the module jars
    loader = setupClassLoader();
    
    // create a session
    session = new CellClientSession(server, loader) {
        @Override
        protected CellCache createCellCache() {
            getCellCacheConnection().addListener(boundsPanel);
            return boundsPanel;
        }
    };
    
    // load any client plugins from that class loader
    Iterator<ClientPlugin> it = Service.providers(ClientPlugin.class,
                                                  loader);
    while (it.hasNext()) {
        ClientPlugin plugin = it.next();
        plugin.initialize(session);
    }

    boundsPanel.setSession(session);
    
    localAvatar = session.getLocalAvatar();
            
    try {
        session.login(loginParams);
    } catch (LoginFailureException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:62,代码来源:CellBoundsViewer.java



注:本文中的sun.misc.Service类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NamenodeRole类代码示例发布时间:2022-05-22
下一篇:
Java RichText类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap