use of org.osgi.service.cm.Configuration in project aries by apache.
the class ManagedServiceFactoryTest method test3.
@Test
public void test3() throws Exception {
Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory3", null);
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("a", "5");
cf.update(props);
@SuppressWarnings("rawtypes") ServiceReference sr = getServiceRef(Foo.class, "(&(key=foo3)(a=5))");
assertNotNull(sr);
Foo foo = (Foo) context().getService(sr);
assertNotNull(foo);
assertEquals(5, foo.getA());
assertEquals("default", foo.getB());
assertEquals("5", sr.getProperty("a"));
assertNull(sr.getProperty("b"));
props = new Hashtable<String, String>();
props.put("a", "5");
props.put("b", "foo");
cf.update(props);
// Update after creation
Thread.sleep(500);
assertEquals(5, foo.getA());
assertEquals("foo", foo.getB());
// Update of service properties
assertEquals("5", sr.getProperty("a"));
assertEquals("foo", sr.getProperty("b"));
cf.delete();
}
use of org.osgi.service.cm.Configuration in project aries by apache.
the class ManagedServiceFactoryTest method test1.
@Test
public void test1() throws Exception {
Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory", null);
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("a", "5");
cf.update(props);
@SuppressWarnings("rawtypes") ServiceReference sr = getServiceRef(Foo.class, "(key=foo1)");
Foo foo = (Foo) context().getService(sr);
assertNotNull(foo);
assertEquals(5, foo.getA());
assertEquals("default", foo.getB());
assertEquals("5", sr.getProperty("a"));
assertNull(sr.getProperty("b"));
props = new Hashtable<String, String>();
props.put("a", "5");
props.put("b", "foo");
cf.update(props);
Thread.sleep(500);
// No update of bean after creation
assertEquals(5, foo.getA());
assertEquals("default", foo.getB());
// Only initial update of service properties
assertEquals("5", sr.getProperty("a"));
assertNull(sr.getProperty("b"));
}
use of org.osgi.service.cm.Configuration in project aries by apache.
the class TestConfigAdmin method testManagedServiceFactory.
@SuppressWarnings("rawtypes")
@Test
public void testManagedServiceFactory() throws Exception {
Configuration cf = ca.createFactoryConfiguration("blueprint-sample-managed-service-factory", null);
cf.update(getConfig1());
startTestBundle();
// Make sure only one service is registered
// Ask the service registry, not the container, since the container might have got it wrong :)
Foo foo = context().getService(Foo.class, "(service.pid=blueprint-sample-managed-service-factory.*)");
ServiceReference[] refs = context().getAllServiceReferences(Foo.class.getName(), "(service.pid=blueprint-sample-managed-service-factory.*)");
assertNotNull("No services were registered for the managed service factory", refs);
assertEquals("Multiple services were registered for the same pid.", 1, refs.length);
}
use of org.osgi.service.cm.Configuration in project aries by apache.
the class ConfigAdminContentHandler method start.
@Override
public void start(String symbolicName, String contentType, Subsystem subsystem, Coordination coordination) {
Dictionary<String, Object> configuration = configurations.get(symbolicName);
if (configuration == null) {
coordination.fail(new Exception("Cannot start configuration " + symbolicName + " for subsystem " + subsystem.getSymbolicName() + " it was not previously loaded"));
return;
}
try {
ConfigurationAdmin cm = cmTracker.getService();
if (cm == null) {
coordination.fail(new Exception("No Configuration Admin Service found. Cannot apply configuration " + symbolicName + " to subsystem " + subsystem.getSymbolicName()));
return;
}
Configuration[] matchingConfs = cm.listConfigurations(ctx.createFilter("(service.pid=" + symbolicName + ")").toString());
if (matchingConfs == null || matchingConfs.length == 0) {
// No configuration exists: create a new one.
Configuration conf = cm.getConfiguration(symbolicName, "?");
conf.update(configuration);
}
// Update has happened, we can forget the configuration data now
configurations.remove(symbolicName);
} catch (InvalidSyntaxException e) {
// Unlikely to happen.
coordination.fail(new Exception("Failed to list existing configurations for " + symbolicName + " in subsystem " + subsystem.getSymbolicName(), e));
} catch (IOException e) {
coordination.fail(new Exception("Problem applying configuration " + symbolicName + " in subsystem " + subsystem.getSymbolicName(), e));
}
}
use of org.osgi.service.cm.Configuration in project aries by apache.
the class ConfigurationAdmin method createFactoryConfigurationForLocation.
/**
* @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#createFactoryConfigurationForLocation(java.lang.String, java.lang.String)
*/
public String createFactoryConfigurationForLocation(String factoryPid, String location) throws IOException {
if (factoryPid == null || factoryPid.length() < 1) {
throw new IOException("Argument factoryPid cannot be null or empty");
}
Configuration config = configurationAdmin.createFactoryConfiguration(factoryPid);
config.setBundleLocation(location);
return config.getPid();
}
Aggregations