本文整理汇总了Java中org.osgi.service.cm.ConfigurationEvent类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationEvent类的具体用法?Java ConfigurationEvent怎么用?Java ConfigurationEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationEvent类属于org.osgi.service.cm包,在下文中一共展示了ConfigurationEvent类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: configurationEvent
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
@Override
public void configurationEvent(final ConfigurationEvent event) {
final int type = event.getType();
final String pid = event.getPid();
if (type == CM_UPDATED) {
final Map<String, Boolean> configuredFeatures = getConfiguredFeatures(pid, configurationAdmin);
for (final Entry<String, Boolean> entry : configuredFeatures.entrySet()) {
final String featureID = entry.getKey();
final boolean isEnabled = entry.getValue();
final Collection<Feature> features = allFeatures.get(pid);
//@formatter:off
features.stream()
.filter(f -> f.id.equalsIgnoreCase(featureID))
.peek(f -> logger.log(LOG_INFO, String.format("Updated feature [%s] to [%b]", f.toString(), isEnabled)))
.forEach(f -> f.isEnabled = isEnabled);
//@formatter:on
}
} else {
allFeatures.removeAll(pid);
}
}
开发者ID:amitjoy,项目名称:feature-flags-for-osgi,代码行数:22,代码来源:FeatureManagerProvider.java
示例2: configurationEvent
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
@Override
public void configurationEvent(ConfigurationEvent event) {
if (StringUtils.equals(OSGI_MGR_PID, event.getPid())) {
switch (event.getType()) {
case CM_DELETED:
OSGiConsolePasswordVault.INSTANCE.setPassword(null);
break;
case CM_UPDATED:
this.handleOSGiManagerPwd(event.getPid());
break;
default:
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ignoring the ConfigurationEvent type: [{}]", event.getType());
}
break;
}
}
}
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:19,代码来源:OSGiManagerConfigListener.java
示例3: configurationEvent
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
/**
* @{inheritDoc
*
* Whenever a {@link Configuration} is updated all items for
* the given <code>pid</code> are queried and updated. Since
* the {@link ConfigurationEvent} contains no information which
* key changed we have to post updates for all configured
* items.
*/
@Override
public void configurationEvent(ConfigurationEvent event) {
// we do only care for updates of existing configs!
if (ConfigurationEvent.CM_UPDATED == event.getType()) {
try {
Configuration config = configAdmin.getConfiguration(event.getPid());
for (ConfigAdminBindingProvider provider : this.providers) {
for (ConfigAdminBindingConfig bindingConfig : provider.getBindingConfigByPid(event.getPid())) {
postUpdate(config, bindingConfig);
}
}
} catch (IOException ioe) {
logger.warn("Fetching configuration for pid '" + event.getPid() + "' failed", ioe);
}
}
}
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:ConfigAdminBinding.java
示例4: configurationEvent
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
@Override
public void configurationEvent(ConfigurationEvent event) {
try {
ConfigurationEventProperties cep = new ConfigurationEventProperties();
cep.factoryPid = event.getFactoryPid();
cep.pid = event.getPid();
if (ConfigurationEvent.CM_DELETED != event.getType()) {
Configuration configuration = cm.getConfiguration(event
.getPid());
cep.location = configuration.getBundleLocation();
Dictionary<String, Object> properties = configuration
.getProperties();
if (properties == null) {
cep.properties = new HashMap<>();
} else
cep.properties = toMap(properties);
}
ea.postEvent(new Event(TOPIC, dtos.asMap(cep)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:osgi,项目名称:osgi.enroute.examples,代码行数:23,代码来源:CmApplication.java
示例5: configurationEvent
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
/**
* @{inheritDoc
*
* Whenever a {@link Configuration} is updated all items for
* the given <code>pid</code> are queried and updated. Since
* the {@link ConfigurationEvent} contains no information which
* key changed we have to post updates for all configured
* items.
*/
@Override
public void configurationEvent(ConfigurationEvent event) {
// we do only care for updates of existing configs!
if (ConfigurationEvent.CM_UPDATED == event.getType()) {
try {
Configuration config = configAdmin.getConfiguration(event.getPid());
for (ConfigAdminBindingProvider provider : this.providers) {
for (ConfigAdminBindingConfig bindingConfig : provider.getBindingConfigByPid(event.getPid())) {
postUpdate(config, bindingConfig);
}
}
} catch (IOException ioe) {
logger.warn("Fetching configuration for pid '" + event.getPid() + "' failed", ioe);
}
}
}
开发者ID:openhab,项目名称:openhab1-addons,代码行数:26,代码来源:ConfigAdminBinding.java
示例6: configurationEvent
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
@Override
public void configurationEvent(ConfigurationEvent event) {
System.out.println("Configuration Event "
+ getType(event.getType())
+ " "
+ (event.getFactoryPid() != null ? event.getFactoryPid() + "::"
: "") + event.getPid());
}
开发者ID:osgi,项目名称:osgi.enroute.examples,代码行数:9,代码来源:ConfigurationListenerExample.java
示例7: getType
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
private String getType(int type) {
switch (type) {
case ConfigurationEvent.CM_DELETED:
return "deleted";
case ConfigurationEvent.CM_LOCATION_CHANGED:
return "location changed";
case ConfigurationEvent.CM_UPDATED:
return "updated";
default:
return "?";
}
}
开发者ID:osgi,项目名称:osgi.enroute.examples,代码行数:13,代码来源:ConfigurationListenerExample.java
示例8: configurationEvent
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
@Override
// [TODO] #47 Revisit configurationEvent on JmxAttributeProvider
// This is an asynchronous callback. How is data integrity preserved?
// Should this depend the the lifecycle of dependent components?
public void configurationEvent(ConfigurationEvent event) {
String pid = event.getPid();
if (pid.equals(MANAGEMENT_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
processConfiguration();
}
}
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:11,代码来源:KarafJmxAttributeProvider.java
示例9: configurationEvent
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
public void configurationEvent(ConfigurationEvent event) {
String pid = event.getPid();
ResourceEvent resourceEvent;
ConfigurationResource configurationResource;
try {
Configuration configuration = m_configAdmin.getConfiguration(pid);
if (!m_configurationResourceMap.containsKey(pid)) {
configurationResource = new ConfigurationResource(configuration);
synchronized (m_lock ) {
m_configurationResourceMap.put(pid, configurationResource);
}
resourceEvent = ResourceEvent.CREATED;
} else {
synchronized (m_lock ) {
configurationResource = m_configurationResourceMap.get(pid);
}
if (event.getType() != ConfigurationEvent.CM_DELETED) {
resourceEvent = ResourceEvent.UPDATED;
} else {
resourceEvent = ResourceEvent.DELETED;
synchronized (m_lock ) {
m_configurationResourceMap.remove(pid);
}
}
}
Everest.postResource(resourceEvent, configurationResource);
} catch (IOException e) {
// something gone wrong
//TODO
e.printStackTrace();
}
}
开发者ID:ow2-chameleon,项目名称:everest,代码行数:34,代码来源:ConfigAdminResourceManager.java
示例10: getConfiguration
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的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
示例11: testConfigurationEventUpdated
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
@Test
public void testConfigurationEventUpdated() throws Exception {
final FeatureManagerProvider manager = new FeatureManagerProvider();
manager.setConfigurationAdmin(configurationAdmin);
manager.setMetaTypeService(metaTypeService);
manager.activate(bundleContext1);
final MetaTypeExtender extender = manager.getExtender();
final String[] pids = new String[] { "a" };
final BundleEvent bundleEvent = new BundleEvent(BundleEvent.STARTED, bundle);
when(metaTypeService.getMetaTypeInformation(bundle)).thenReturn(metaTypeInfo);
when(metaTypeInfo.getPids()).thenReturn(pids);
when(metaTypeInfo.getObjectClassDefinition("a", null)).thenReturn(ocd);
when(ocd.getAttributeDefinitions(ALL)).thenReturn(new AttributeDefinition[] { ad });
mockADWithoutDefaultValue();
when(bundleContext1.getBundle(0)).thenReturn(systemBundle);
when(bundle.getState()).thenReturn(ACTIVE);
when(bundle.getBundleContext()).thenReturn(bundleContext1);
extender.addingBundle(bundle, bundleEvent);
Thread.sleep(1000);
FeatureDTO feature = manager.getFeatures().collect(Collectors.toList()).get(0);
assertEquals(FEATURE_ID, feature.id);
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
feature = manager.getFeatures(FEATURE_ID).findFirst().get();
assertEquals(FEATURE_ID, feature.id);
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
feature = manager.getFeatures(FEATURE_ID).findAny().get();
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
final Map<String, Object> properties = ImmutableMap.<String, Object> builder()
.put("osgi.feature.myfeature", true).build();
when(configurationAdmin.getConfiguration("a", "?")).thenReturn(configuration);
when(configuration.getProperties()).thenReturn(new MapToDictionary(properties));
final ConfigurationEvent configEvent = new ConfigurationEvent(reference, 1, null, "a");
manager.configurationEvent(configEvent);
final FeatureDTO updatedFeature = manager.getFeatures(FEATURE_ID).findAny().get();
assertTrue(updatedFeature.isEnabled);
}
开发者ID:amitjoy,项目名称:feature-flags-for-osgi,代码行数:55,代码来源:FeatureManagerProviderTest.java
示例12: testConfigurationEventDeleted
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
@Test
public void testConfigurationEventDeleted() throws Exception {
final FeatureManagerProvider manager = new FeatureManagerProvider();
manager.setConfigurationAdmin(configurationAdmin);
manager.setMetaTypeService(metaTypeService);
manager.activate(bundleContext1);
final MetaTypeExtender extender = manager.getExtender();
final String[] pids = new String[] { "a" };
final BundleEvent bundleEvent = new BundleEvent(BundleEvent.STARTED, bundle);
when(metaTypeService.getMetaTypeInformation(bundle)).thenReturn(metaTypeInfo);
when(metaTypeInfo.getPids()).thenReturn(pids);
when(metaTypeInfo.getObjectClassDefinition("a", null)).thenReturn(ocd);
when(ocd.getAttributeDefinitions(ALL)).thenReturn(new AttributeDefinition[] { ad });
mockADWithoutDefaultValue();
when(bundleContext1.getBundle(0)).thenReturn(systemBundle);
when(bundle.getState()).thenReturn(ACTIVE);
when(bundle.getBundleContext()).thenReturn(bundleContext1);
extender.addingBundle(bundle, bundleEvent);
Thread.sleep(1000);
FeatureDTO feature = manager.getFeatures().collect(Collectors.toList()).get(0);
assertEquals(FEATURE_ID, feature.id);
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
feature = manager.getFeatures(FEATURE_ID).findFirst().get();
assertEquals(FEATURE_ID, feature.id);
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
feature = manager.getFeatures(FEATURE_ID).findAny().get();
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
final ConfigurationEvent configEvent = new ConfigurationEvent(reference, 2, null, "a");
manager.configurationEvent(configEvent);
final List<FeatureDTO> newFeatures = manager.getFeatures().collect(Collectors.toList());
assertTrue(newFeatures.isEmpty());
}
开发者ID:amitjoy,项目名称:feature-flags-for-osgi,代码行数:49,代码来源:FeatureManagerProviderTest.java
示例13: testConfigurationEventUpdatedButIOException
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的package包/类
@Test
public void testConfigurationEventUpdatedButIOException() throws Exception {
final FeatureManagerProvider manager = new FeatureManagerProvider();
manager.setConfigurationAdmin(configurationAdmin);
manager.setMetaTypeService(metaTypeService);
manager.activate(bundleContext1);
final MetaTypeExtender extender = manager.getExtender();
final String[] pids = new String[] { "a" };
final BundleEvent bundleEvent = new BundleEvent(BundleEvent.STARTED, bundle);
when(metaTypeService.getMetaTypeInformation(bundle)).thenReturn(metaTypeInfo);
when(metaTypeInfo.getPids()).thenReturn(pids);
when(metaTypeInfo.getObjectClassDefinition("a", null)).thenReturn(ocd);
when(ocd.getAttributeDefinitions(ALL)).thenReturn(new AttributeDefinition[] { ad });
mockADWithoutDefaultValue();
when(bundleContext1.getBundle(0)).thenReturn(systemBundle);
when(bundle.getState()).thenReturn(ACTIVE);
when(bundle.getBundleContext()).thenReturn(bundleContext1);
extender.addingBundle(bundle, bundleEvent);
Thread.sleep(1000);
FeatureDTO feature = manager.getFeatures().collect(Collectors.toList()).get(0);
assertEquals(FEATURE_ID, feature.id);
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
feature = manager.getFeatures(FEATURE_ID).findFirst().get();
assertEquals(FEATURE_ID, feature.id);
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
feature = manager.getFeatures(FEATURE_ID).findAny().get();
assertEquals(FEATURE_DESC, feature.description);
assertFalse(feature.isEnabled);
when(configurationAdmin.getConfiguration("a", "?")).thenThrow(IOException.class);
final ConfigurationEvent configEvent = new ConfigurationEvent(reference, 1, null, "a");
manager.configurationEvent(configEvent);
final FeatureDTO updatedFeature = manager.getFeatures(FEATURE_ID).findAny().get();
assertFalse(updatedFeature.isEnabled);
}
开发者ID:amitjoy,项目名称:feature-flags-for-osgi,代码行数:51,代码来源:FeatureManagerProviderTest.java
示例14: testSimple
import org.osgi.service.cm.ConfigurationEvent; //导入依赖的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.ConfigurationEvent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论