Search in sources :

Example 1 with ConfigurationHandlerDescription

use of org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription in project felix by apache.

the class AdvancedTrackerAndRankerInterceptor method open.

@Override
public void open(DependencyModel dependency) {
    super.open(dependency);
    ConfigurationHandlerDescription handler = (ConfigurationHandlerDescription) dependency.getComponentInstance().getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:properties");
    handler.addListener(this);
}
Also used : ConfigurationHandlerDescription(org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription)

Example 2 with ConfigurationHandlerDescription

use of org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription in project felix by apache.

the class TestArchitecture method testArchitectureForInstance1.

@Test
public void testArchitectureForInstance1() {
    Architecture arch = osgiHelper.getServiceObject(Architecture.class, "(architecture.instance=instance)");
    assertNotNull(arch);
    // Test on String representation.
    String desc = arch.getInstanceDescription().getDescription().toString();
    assertTrue(desc.contains("managed.service.pid=\"FooProvider-3\""));
    // Test on handler description
    ConfigurationHandlerDescription hd = (ConfigurationHandlerDescription) arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:properties");
    assertNotNull(hd);
    assertEquals(2, hd.getProperties().length);
    assertEquals("FooProvider-3", hd.getManagedServicePid());
    // Check the getInstance() method
    assertSame(arch.getInstanceDescription().getInstance(), instance1);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) ConfigurationHandlerDescription(org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription) Test(org.junit.Test)

Example 3 with ConfigurationHandlerDescription

use of org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription in project felix by apache.

the class AdvancedTrackerAndRankerInterceptor method close.

@Override
public void close(DependencyModel dependency) {
    super.close(dependency);
    ConfigurationHandlerDescription handler = (ConfigurationHandlerDescription) dependency.getComponentInstance().getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:properties");
    handler.removeListener(this);
}
Also used : ConfigurationHandlerDescription(org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription)

Example 4 with ConfigurationHandlerDescription

use of org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription in project felix by apache.

the class TestPropagation method testPropagationFromConfigurationAdminWhenCreatingTheInstance.

@Test
public void testPropagationFromConfigurationAdminWhenCreatingTheInstance() throws IOException {
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("message", "message");
    props.put("propagated", "propagated");
    props.put(".private", "wow");
    Configuration configuration = admin.createFactoryConfiguration(factoryName, "?");
    configuration.update(props);
    ServiceReference ref = osgiHelper.waitForService(FooService.class.getName(), "(instance.name=" + configuration.getPid() + ")", 1000);
    // Check the propagation
    assertEquals(ref.getProperty("propagated"), "propagated");
    assertEquals(ref.getProperty("message"), "message");
    assertNull(ref.getProperty(".private"));
    assertNull(ref.getProperty("private"));
    // Check the the .private property has the right value
    ConfigurationHandlerDescription desc = (ConfigurationHandlerDescription) ipojoHelper.getArchitectureByName(configuration.getPid()).getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:properties");
    PropertyDescription prop = desc.getPropertyByName(".private");
    assertEquals(prop.getValue(), "wow");
    // Update the property
    props.put("message", "message2");
    props.put("propagated", "propagated2");
    props.put(".private", "wow2");
    configuration.update(props);
    grace();
    ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), configuration.getPid());
    // Check the propagation
    assertEquals(ref.getProperty("propagated"), "propagated2");
    assertEquals(ref.getProperty("message"), "message2");
    desc = (ConfigurationHandlerDescription) ipojoHelper.getArchitectureByName(configuration.getPid()).getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:properties");
    prop = desc.getPropertyByName(".private");
    assertEquals(prop.getValue(), "wow2");
    configuration.delete();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PropertyDescription(org.apache.felix.ipojo.architecture.PropertyDescription) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfigurationHandlerDescription(org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 5 with ConfigurationHandlerDescription

use of org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription in project felix by apache.

the class TestArchitecture method testArchitectureForInstance2.

@Test
public void testArchitectureForInstance2() {
    Architecture arch = osgiHelper.getServiceObject(Architecture.class, "(architecture.instance=instance-2)");
    assertNotNull(arch);
    // Test on String representation.
    String desc = arch.getInstanceDescription().getDescription().toString();
    assertTrue(desc.contains("managed.service.pid=\"instance\""));
    // Test on handler description
    ConfigurationHandlerDescription hd = (ConfigurationHandlerDescription) arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:properties");
    assertNotNull(hd);
    assertEquals(2, hd.getProperties().length);
    assertEquals("instance", hd.getManagedServicePid());
    // Check the getInstance() method
    assertSame(arch.getInstanceDescription().getInstance(), instance2);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) ConfigurationHandlerDescription(org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription) Test(org.junit.Test)

Aggregations

ConfigurationHandlerDescription (org.apache.felix.ipojo.handlers.configuration.ConfigurationHandlerDescription)5 Test (org.junit.Test)3 Architecture (org.apache.felix.ipojo.architecture.Architecture)2 Hashtable (java.util.Hashtable)1 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)1 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)1 ServiceReference (org.osgi.framework.ServiceReference)1 Configuration (org.osgi.service.cm.Configuration)1