use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class TestObedience method testDisposeAfterFactoryInvalidation.
@Test
public void testDisposeAfterFactoryInvalidation() {
ComponentFactory cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
assertNotNull("Check factory availability -1", cf);
assertEquals("Check factory state -1", Factory.VALID, cf.getState());
ServiceReference ref_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "SimpleInstance");
assertNotNull("Check Architecture availability -1", ref_arch);
HandlerManagerFactory hf = (HandlerManagerFactory) ipojoHelper.getHandlerFactory("controller");
assertNotNull("Check handler availability -1", hf);
assertEquals("Check handler state -1", Factory.VALID, hf.getState());
// Stop the handler
hf.stop();
HandlerManagerFactory hf2 = (HandlerManagerFactory) ipojoHelper.getFactoryHelper().getHandlerFactory("controller", 1, false);
assertNull("Check handler availability -2", hf2);
// Check the factory invalidity
cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
assertNotNull("Check factory availability -2", cf);
assertEquals("Check factory state -2", Factory.INVALID, cf.getState());
// Check the instance disappearance, the instance was disposed.
assertFalse("Check Architecture availability -1", ipojoHelper.isServiceAvailableByName(Architecture.class.getName(), "SimpleInstance"));
// Restart the handler
hf.start();
hf2 = (HandlerManagerFactory) ipojoHelper.getHandlerFactory("controller");
assertNotNull("Check handler availability -3", hf2);
// Check the factory state
cf = (ComponentFactory) ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.SimpleType");
assertNotNull("Check factory availability -3", cf);
assertEquals("Check factory state -3", Factory.VALID, cf.getState());
// Check the instance re-creation
ref_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "SimpleInstance");
assertNotNull("Check Architecture availability -3", ref_arch);
}
use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class PrimitiveComponentType method createFactory.
/**
* Creates the component factory.
*/
private void createFactory() {
ensureValidity();
byte[] clazz = manipulate();
Element meta = generateComponentMetadata();
meta.addElement(m_manipulation);
try {
if (m_alreadyManipulated) {
// Already manipulated
m_factory = new ComponentFactory(m_context, meta);
} else {
m_factory = new ComponentFactory(m_context, clazz, meta);
m_factory.setUseFactoryClassloader(true);
}
m_factory.start();
} catch (ConfigurationException e) {
throw new IllegalStateException("An exception occurs during factory initialization", e);
}
}
use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class TestComp0 method setUp.
@Before
public void setUp() {
tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
tataFactory2.stop();
tataFactory.stop();
Properties props = new Properties();
props.put("instance.name", "toto provider");
try {
totoProv = totoFactory.createComponentInstance(props);
} catch (Exception e) {
fail("Cannot create an instance : " + e.getMessage());
}
Properties props3 = new Properties();
props3.put("instance.name", "toto provider 2");
try {
totoProv2 = totoFactory.createComponentInstance(props3);
} catch (Exception e) {
fail("Cannot create an instance : " + e.getMessage());
}
totoProv.stop();
totoProv2.stop();
Factory factory = ipojoHelper.getFactory("comp-0");
Properties props2 = new Properties();
props2.put("instance.name", "ff");
try {
under = factory.createComponentInstance(props2);
} catch (Exception e) {
e.printStackTrace();
fail("Cannot create an instance : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class TestComp1 method setUp.
@Before
public void setUp() {
tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
tataFactory2.stop();
tataFactory.stop();
Properties props = new Properties();
props.put("instance.name", "toto provider");
try {
totoProv = totoFactory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
}
Properties props3 = new Properties();
props3.put("instance.name", "toto provider 2");
try {
totoProv2 = totoFactory.createComponentInstance(props3);
} catch (Exception e) {
e.printStackTrace();
}
totoProv.stop();
totoProv2.stop();
Factory factory = ipojoHelper.getFactory("comp-1");
Properties props2 = new Properties();
try {
under = factory.createComponentInstance(props2);
} catch (Exception e) {
fail("Cannot create the instance : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.ComponentFactory in project felix by apache.
the class TestComp3 method setUp.
@Before
public void setUp() {
tataFactory = (ComponentFactory) ipojoHelper.getFactory("tata");
totoFactory = (ComponentFactory) ipojoHelper.getFactory("toto");
tataFactory2 = (ComponentFactory) ipojoHelper.getFactory("comp-6");
tataFactory2.stop();
tataFactory.stop();
Properties props = new Properties();
props.put("instance.name", "toto provider");
try {
totoProv = totoFactory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
}
Properties props3 = new Properties();
props3.put("instance.name", "toto provider 2");
try {
totoProv2 = totoFactory.createComponentInstance(props3);
} catch (Exception e) {
e.printStackTrace();
}
totoProv.stop();
totoProv2.stop();
Factory factory = ipojoHelper.getFactory("comp-3");
Properties props2 = new Properties();
props2.put("instance.name", "ff");
try {
under = factory.createComponentInstance(props2);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations