当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurationListener类代码示例

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


ConfigurationListener类属于org.osgi.service.cm包,在下文中一共展示了ConfigurationListener类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: canCharge

import org.osgi.service.cm.ConfigurationListener; //导入依赖的package包/类
public static boolean canCharge(){
    try{
        ConfigAdminResourceManager.class.getClassLoader().loadClass(ConfigurationAdmin.class.getName());
        ConfigAdminResourceManager.class.getClassLoader().loadClass(ConfigurationListener.class.getName());
    } catch (Throwable t) { //NO_SONAR
        return false;
    }
    return true;
}
 
开发者ID:ow2-chameleon,项目名称:everest,代码行数:10,代码来源:ConfigAdminResourceManager.java

示例2: getConfiguration

import org.osgi.service.cm.ConfigurationListener; //导入依赖的package包/类
/**
 * Returns a map containing the Configuration Admin entry with given pid. Waits until a non-null (initialized)
 * object is returned if initTimeout is bigger then 0.
 * 
 * @param bundleContext
 * @param pid
 * @param initTimeout
 * @return
 * @throws IOException
 */
public static Map getConfiguration(BundleContext bundleContext, final String pid, long initTimeout)
		throws IOException {
	ServiceReference ref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
	if (ref != null) {
		ConfigurationAdmin cm = (ConfigurationAdmin) bundleContext.getService(ref);
		if (cm != null) {
			Dictionary dict = cm.getConfiguration(pid).getProperties();
			// if there are properties or no timeout, return as is
			if (dict != null || initTimeout == 0) {
				return new MapBasedDictionary(dict);
			}
			// no valid props, register a listener and start waiting
			final Object monitor = new Object();
			Dictionary<String, Object> props = new Hashtable<String, Object>();
			props.put(Constants.SERVICE_PID, pid);
			
			ServiceRegistration reg =
					bundleContext.registerService(ConfigurationListener.class.getName(),
							new ConfigurationListener() {
								public void configurationEvent(ConfigurationEvent event) {
									if (ConfigurationEvent.CM_UPDATED == event.getType()
											&& pid.equals(event.getPid())) {
										synchronized (monitor) {
											monitor.notify();
										}
									}
								}
							}, props);

			try {
				// try to get the configuration one more time (in case the update was fired before the service was
				// registered)
				dict = cm.getConfiguration(pid).getProperties();
				if (dict != null) {
					return new MapBasedDictionary(dict);
				}

				// start waiting
				synchronized (monitor) {
					try {
						monitor.wait(initTimeout);
					} catch (InterruptedException ie) {
						// consider the timeout has passed
					}
				}

				// return whatever is available (either we timed out or an update occured)
				return new MapBasedDictionary(cm.getConfiguration(pid).getProperties());

			} finally {
				OsgiServiceUtils.unregisterService(reg);
			}
		}
	}
	return Collections.EMPTY_MAP;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:67,代码来源:CMUtils.java

示例3: registerListenerService

import org.osgi.service.cm.ConfigurationListener; //导入依赖的package包/类
public void registerListenerService(BundleContext context){
    m_configurationListenerServiceRegistration = context.registerService(ConfigurationListener.class/*"org.osgi.service.cm.ConfigurationListener"*/, m_configListener, null);
}
 
开发者ID:ow2-chameleon,项目名称:everest,代码行数:4,代码来源:ConfigAdminResourceManager.java

示例4: testSimple

import org.osgi.service.cm.ConfigurationListener; //导入依赖的package包/类
public void testSimple() throws Exception {
	final Semaphore s = new Semaphore(0);

	context.registerService(ConfigurationListener.class, new ConfigurationListener() {

		@Override
		public void configurationEvent(ConfigurationEvent event) {
			switch (event.getPid()) {
				case "singleton" :
					s.release();
					break;

				default :
					if (event.getFactoryPid().equals("factory")) {
						s.release();
					}
					break;
			}
		}
	}, null);

	Bundle a = doBundleFor("a.json");

	assertEquals("check if we're running", Bundle.ACTIVE, a.getState());

	//
	// See if we got our 3 updates
	//
	
	if (!s.tryAcquire(3, 100, TimeUnit.SECONDS)) {
		fail("Cannot find updates");
	}

	checkConfigs(1,2);
	
	//
	// Check that the configs are persistent
	//
	
	a.uninstall();
	
	checkConfigs(1,2);
	
	
	//
	// Now we make a new bundle that will set a new port for the singleton (10)
	// and will change the first factory, ignore the second, and add a third
	//
	
	Bundle b = doBundleFor("b.json");
	
	if (!s.tryAcquire(4, 100, TimeUnit.SECONDS)) {
		fail("Cannot find updates");
	}
	
	checkConfigs(10,3);
	b.uninstall();
	
}
 
开发者ID:osgi,项目名称:bundles,代码行数:60,代码来源:ConfigurerTest.java


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