use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestDependencyArchitecture method testMultipleOptionalDependency.
@Test
public void testMultipleOptionalDependency() {
ServiceReference arch_dep = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance4.getInstanceName());
assertNotNull("Check architecture availability", arch_dep);
PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.VALID);
// Check dependency handler invalidity
DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler invalidity", dhd.isValid());
// Check dependency metadata
assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
assertTrue("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
fooProvider1.start();
ServiceReference arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check architecture availability", arch_ps1);
PrimitiveInstanceDescription id_ps1 = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
ProvidedServiceHandlerDescription psh = getPSDesc(id_ps1);
assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
// Start a second foo service provider
fooProvider2.start();
arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
ServiceReference arch_ps2 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider2.getInstanceName());
assertNotNull("Check architecture availability", arch_ps1);
assertNotNull("Check architecture 2 availability", arch_ps2);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
PrimitiveInstanceDescription id_ps2 = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps2)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
assertTrue("Check instance 2 invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref - 3 ", dhd.getDependencies()[0].getServiceReferences().size(), 2);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
// id_ps2 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
ProvidedServiceHandlerDescription psh1 = getPSDesc(id_ps1);
ProvidedServiceHandlerDescription psh2 = getPSDesc(id_ps2);
assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
assertEquals("Check POJO creation", id_ps2.getCreatedObjects().length, 1);
fooProvider2.stop();
arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check architecture availability", arch_ps1);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
psh = getPSDesc(id_ps1);
assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
fooProvider1.stop();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler invalidity", dhd.isValid());
fooProvider2.start();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
arch_ps2 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider2.getInstanceName());
assertNotNull("Check architecture availability", arch_ps2);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
psh = getPSDesc(id_ps2);
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance4.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
psh = getPSDesc(id_ps2);
fooProvider2.stop();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler invalidity", dhd.isValid());
id_dep = null;
cs = null;
getContext().ungetService(arch_dep);
getContext().ungetService(cs_ref);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestDependencyArchitecture method testMultipleDependency.
@Test
public void testMultipleDependency() {
ServiceReference arch_dep = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance3.getInstanceName());
assertNotNull("Check architecture availability", arch_dep);
PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
// Check dependency handler invalidity
DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
DependencyDescription dd = getDependencyDescBySpecification(id_dep, FooService.class.getName());
assertFalse("Check dependency handler invalidity", dhd.isValid());
assertTrue("Check dependency invalidity", dd.getState() == Dependency.UNRESOLVED);
// Check dependency metadata
assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
assertTrue("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
assertFalse("Check dependency optionality", dhd.getDependencies()[0].isOptional());
assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
assertEquals("Check dependency interface", dd.getSpecification(), FooService.class.getName());
assertTrue("Check dependency cardinality", dd.isMultiple());
assertFalse("Check dependency optionality", dd.isOptional());
assertNull("Check dependency ref -1", dd.getServiceReferences());
assertFalse("Check dependency proxy", dhd.getDependencies()[0].isProxy());
fooProvider1.start();
ServiceReference arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check architecture availability", arch_ps1);
PrimitiveInstanceDescription id_ps1 = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
assertTrue("Check instance validity - 1", id_ps1.getState() == ComponentInstance.VALID);
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
assertEquals("Check used ref - 1 (" + dhd.getDependencies()[0].getUsedServices().size() + ")", dhd.getDependencies()[0].getUsedServices().size(), 0);
ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
ProvidedServiceHandlerDescription psh = getPSDesc(id_ps1);
assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
// Start a second foo service provider
fooProvider2.start();
arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
ServiceReference arch_ps2 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider2.getInstanceName());
assertNotNull("Check architecture availability", arch_ps1);
assertNotNull("Check architecture 2 availability", arch_ps2);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
PrimitiveInstanceDescription id_ps2 = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps2)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_ps1.getState() == ComponentInstance.VALID);
assertTrue("Check instance 2 invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref - 3 ", dhd.getDependencies()[0].getServiceReferences().size(), 2);
// provider 2 not already used
assertEquals("Check used ref - 2 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
// id_ps2 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
ProvidedServiceHandlerDescription psh1 = getPSDesc(id_ps1);
ProvidedServiceHandlerDescription psh2 = getPSDesc(id_ps2);
assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
assertEquals("Check POJO creation", id_ps2.getCreatedObjects().length, 1);
assertEquals("Check used ref - 3 (" + dhd.getDependencies()[0].getUsedServices().size() + ")", dhd.getDependencies()[0].getUsedServices().size(), 2);
fooProvider2.stop();
arch_ps1 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check architecture availability", arch_ps1);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
assertTrue("Check instance validity - 1", id_ps1.getState() == ComponentInstance.VALID);
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
assertEquals("Check used ref - 4 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
psh = getPSDesc(id_ps1);
assertEquals("Check POJO creation", id_ps1.getCreatedObjects().length, 1);
assertEquals("Check used ref - 5 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
fooProvider1.stop();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertFalse("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertFalse("Check dependency handler invalidity", dhd.isValid());
fooProvider2.start();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
arch_ps2 = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider2.getInstanceName());
assertNotNull("Check architecture availability", arch_ps1);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
assertTrue("Check instance invalidity - 1", id_ps2.getState() == ComponentInstance.VALID);
psh = getPSDesc(id_ps2);
assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
assertTrue("Check dependency handler validity", dhd.isValid());
assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
assertEquals("Check used ref - 6 ", dhd.getDependencies()[0].getUsedServices().size(), 0);
cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
assertNotNull("Check CheckService availability", cs_ref);
cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Check object graph
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
dhd = getDependencyDesc(id_dep);
// id_ps1 = ((Architecture) osgiHelper.getRawServiceObject(arch_ps1)).getInstanceDescription();
psh = getPSDesc(id_ps2);
assertEquals("Check used ref - 7 ", dhd.getDependencies()[0].getUsedServices().size(), 1);
fooProvider2.stop();
// id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
assertFalse("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
dhd = getDependencyDesc(id_dep);
assertFalse("Check dependency handler invalidity", dhd.isValid());
id_dep = null;
cs = null;
getContext().ungetService(arch_dep);
getContext().ungetService(cs_ref);
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class Dependency method getDependencyDescription.
/**
* Gets the dependency description object attached to
* this dependency.
* @param instance the instance on which searching the dependency
* @return the dependency description attached to this dependency or
* <code>null</code> if the dependency cannot be found.
*/
public DependencyDescription getDependencyDescription(ComponentInstance instance) {
PrimitiveInstanceDescription desc = (PrimitiveInstanceDescription) instance.getInstanceDescription();
if (m_id != null) {
return desc.getDependency(m_id);
}
if (m_specification != null) {
return desc.getDependency(m_specification);
}
DependencyDescription[] deps = desc.getDependencies();
if (deps.length == 1) {
return deps[0];
}
// Cannot determine the dependency.
return null;
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class Property method getPropertyDescription.
/**
* Gets the property description for the current property.
* @param instance the component instance on which looking for the property.
* @return the property description associated with the current property
* or <code>null</code> if not found.
*/
public PropertyDescription getPropertyDescription(ComponentInstance instance) {
PrimitiveInstanceDescription desc = (PrimitiveInstanceDescription) instance.getInstanceDescription();
PropertyDescription[] props = desc.getProperties();
for (int i = 0; i < props.length; i++) {
if ((m_name != null && m_name.equals(props[i].getName())) || (m_field != null && m_field.equals(props[i].getName()))) {
return props[i];
}
}
return null;
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceFactoryTestForImmediate method testCreationAndReconfiguration2.
@Test
public void testCreationAndReconfiguration2() {
// The reconfiguration happens before the service invocation
Configuration configuration = null;
try {
configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
} catch (IOException e) {
fail(e.getMessage());
}
Dictionary props = configuration.getProperties();
if (props == null) {
props = new Properties();
}
props.put("message", "message");
try {
configuration.update(props);
} catch (IOException e) {
fail(e.getMessage());
}
String pid = configuration.getPid();
System.out.println("PID : " + pid);
// Wait for the processing of the first configuration.
grace();
// The instance should be created, wait for the architecture service
osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
props.put("message", "message2");
try {
configuration.update(props);
// Update the configuration ...
grace();
} catch (Exception e) {
fail(e.getMessage());
}
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Check object -2", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
// Invoke
FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = ((Integer) p.get("count")).intValue();
// architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
assertEquals("Assert Message", "message2", mes);
assertEquals("Assert count", 2, count);
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
try {
configuration.delete();
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
assertNull("Check unavailability", ref);
}
Aggregations