Search in sources :

Example 86 with Component

use of org.apache.felix.dm.Component in project felix by apache.

the class ComponentStateListenerTest method testDynamicComponentStateListingLifeCycle.

public void testDynamicComponentStateListingLifeCycle() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a simple service component
    Component s = m.createComponent().setInterface(MyInterface.class.getName(), null).setImplementation(new DynamicComponentStateListeningInstance(e));
    // add it, and since it has no dependencies, it should be activated immediately
    m.add(s);
    // remove it so it gets destroyed
    m.remove(s);
    // ensure we executed all steps inside the component instance
    e.step(10);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 87 with Component

use of org.apache.felix.dm.Component in project felix by apache.

the class ComponentStateListenerTest method testCustomComponentLifeCycleCallbacks.

public void testCustomComponentLifeCycleCallbacks() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a simple service component
    Component s = m.createComponent().setImplementation(new CustomComponentInstance(e)).setCallbacks("a", "b", "c", "d");
    // add it, and since it has no dependencies, it should be activated immediately
    m.add(s);
    // remove it so it gets destroyed
    m.remove(s);
    // ensure we executed all steps inside the component instance
    e.step(6);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 88 with Component

use of org.apache.felix.dm.Component in project felix by apache.

the class ComponentStateListenerTest method testComponentLifeCycleCallbacks.

public void testComponentLifeCycleCallbacks() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a simple service component
    Component s = m.createComponent().setImplementation(new ComponentInstance(e));
    // add it, and since it has no dependencies, it should be activated immediately
    m.add(s);
    // remove it so it gets destroyed
    m.remove(s);
    // ensure we executed all steps inside the component instance
    e.step(6);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 89 with Component

use of org.apache.felix.dm.Component in project felix by apache.

the class ComponentTest method testSimple.

public void testSimple() throws Exception {
    final DependencyManager dm = getDM();
    Component consumer = dm.createComponent();
    consumer.setImplementation(new Consumer()).add(dm.createServiceDependency().setService(Provider.class, "(name=provider2)").setRequired(true).setCallbacks("add", "remove")).add(dm.createServiceDependency().setService(Provider.class, "(name=provider1)").setRequired(true).setAutoConfig("m_autoConfiguredProvider"));
    Dictionary props = new Hashtable();
    props.put("name", "provider1");
    Component provider1 = dm.createComponent().setImplementation(new Provider() {

        public String toString() {
            return "provider1";
        }
    }).setInterface(Provider.class.getName(), props);
    props = new Hashtable();
    props.put("name", "provider2");
    Component provider2 = dm.createComponent().setImplementation(new Provider() {

        public String toString() {
            return "provider2";
        }
    }).setInterface(Provider.class.getName(), props);
    dm.add(provider1);
    dm.add(provider2);
    dm.add(consumer);
    m_ensure.waitForStep(2, 5000);
    dm.remove(provider1);
    dm.remove(provider2);
    m_ensure.waitForStep(5, 5000);
    dm.clear();
}
Also used : Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component)

Example 90 with Component

use of org.apache.felix.dm.Component in project felix by apache.

the class ConfigurationDependencyTest method testFELIX2987.

public void testFELIX2987() {
    // mimics testComponentWithRequiredConfigurationAndServicePropertyPropagation
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component s1 = m.createComponent().setImplementation(new ConfigurationConsumer2(e)).setInterface(Runnable.class.getName(), null).add(m.createConfigurationDependency().setPid(PID).setPropagate(true));
    Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
    Component s3 = m.createComponent().setImplementation(new ConfiguredServiceConsumer(e)).add(m.createServiceDependency().setService(Runnable.class, ("(testkey=testvalue)")).setRequired(true));
    m.add(s1);
    m.add(s2);
    m.add(s3);
    e.waitForStep(4, 5000);
    m.remove(s1);
    m.remove(s2);
    m.remove(s3);
    // ensure we executed all steps inside the component instance
    e.step(6);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Aggregations

Component (org.apache.felix.dm.Component)271 DependencyManager (org.apache.felix.dm.DependencyManager)227 Ensure (org.apache.felix.dm.itest.util.Ensure)91 DependencyManagerActivator.component (org.apache.felix.dm.lambda.DependencyManagerActivator.component)65 Hashtable (java.util.Hashtable)59 Assert (org.junit.Assert)46 Dictionary (java.util.Dictionary)32 ServiceReference (org.osgi.framework.ServiceReference)25 Map (java.util.Map)23 DependencyManagerActivator.aspect (org.apache.felix.dm.lambda.DependencyManagerActivator.aspect)21 Bundle (org.osgi.framework.Bundle)17 ServiceRegistration (org.osgi.framework.ServiceRegistration)17 DependencyManagerActivator.adapter (org.apache.felix.dm.lambda.DependencyManagerActivator.adapter)15 ArrayList (java.util.ArrayList)14 ComponentDeclaration (org.apache.felix.dm.ComponentDeclaration)13 HashMap (java.util.HashMap)12 ServiceDependency (org.apache.felix.dm.ServiceDependency)12 Test (org.junit.Test)11 Properties (java.util.Properties)10 DependencyGraph (org.apache.felix.dm.diagnostics.DependencyGraph)10