Search in sources :

Example 16 with ComponentFactory

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);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) HandlerManagerFactory(org.apache.felix.ipojo.HandlerManagerFactory) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 17 with ComponentFactory

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);
    }
}
Also used : ConfigurationException(org.apache.felix.ipojo.ConfigurationException) Element(org.apache.felix.ipojo.metadata.Element) ComponentFactory(org.apache.felix.ipojo.ComponentFactory)

Example 18 with ComponentFactory

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());
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) Properties(java.util.Properties) Before(org.junit.Before)

Example 19 with ComponentFactory

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());
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) Properties(java.util.Properties) Before(org.junit.Before)

Example 20 with ComponentFactory

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();
    }
}
Also used : Factory(org.apache.felix.ipojo.Factory) ComponentFactory(org.apache.felix.ipojo.ComponentFactory) Properties(java.util.Properties) Before(org.junit.Before)

Aggregations

ComponentFactory (org.apache.felix.ipojo.ComponentFactory)35 Properties (java.util.Properties)27 Before (org.junit.Before)15 Test (org.junit.Test)15 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)14 Factory (org.apache.felix.ipojo.Factory)14 ServiceContext (org.apache.felix.ipojo.ServiceContext)7 Architecture (org.apache.felix.ipojo.architecture.Architecture)5 ServiceReference (org.osgi.framework.ServiceReference)5 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)4 CompositeInstanceDescription (org.apache.felix.ipojo.composite.CompositeInstanceDescription)4 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)4 ConfigurationException (org.apache.felix.ipojo.ConfigurationException)2 InstanceManager (org.apache.felix.ipojo.InstanceManager)2 Element (org.apache.felix.ipojo.metadata.Element)2 ParseException (org.apache.felix.ipojo.parser.ParseException)2 MockBundle (org.apache.felix.ipojo.test.MockBundle)2 Logger (org.apache.felix.ipojo.util.Logger)2 Bundle (org.osgi.framework.Bundle)2 BundleContext (org.osgi.framework.BundleContext)2