Search in sources :

Example 61 with Component

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

the class MultipleServiceDependencyTest method testReplacementCallbacks.

public void testReplacementCallbacks() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component provider = component(m).impl(new ServiceProvider(e)).provides(ServiceInterface.class.getName()).build();
    Component provider2 = component(m).impl(new ServiceProvider2(e)).provides(ServiceInterface.class.getName()).build();
    Component consumer = component(m).impl(new ServiceConsumer(e)).withSvc(ServiceInterface.class, srv -> srv.add("add").remove("remove")).build();
    m.add(provider2);
    m.add(consumer);
    e.waitForStep(3, 15000);
    m.add(provider);
    m.remove(provider2);
    e.step(4);
    e.waitForStep(5, 15000);
    m.remove(provider);
    m.remove(consumer);
    e.waitForStep(6, 15000);
}
Also used : Component(org.apache.felix.dm.Component) Constants(org.osgi.framework.Constants) DependencyManager(org.apache.felix.dm.DependencyManager) DependencyManagerActivator.component(org.apache.felix.dm.lambda.DependencyManagerActivator.component) DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component)

Example 62 with Component

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

the class DynamicCustomIndexTest method doTestUsingDynamicCustomIndex.

private void doTestUsingDynamicCustomIndex() throws Exception {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a provider
    Provider provider = new Provider();
    // activate it
    Component p = m.createComponent().setInterface(Service.class.getName(), null).setImplementation(provider);
    Client consumer = new Client(e);
    Component c = m.createComponent().setImplementation(consumer).add(m.createServiceDependency().setService(Service.class).setRequired(true));
    m.add(p);
    m.add(c);
    e.waitForStep(1, 5000);
    m.remove(p);
    e.waitForStep(2, 5000);
    m.remove(c);
    m.clear();
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component)

Example 63 with Component

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

the class StaticCustomIndexTest method testUsingStaticCustomIndex.

public void testUsingStaticCustomIndex() throws Exception {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a provider
    Provider provider = new Provider();
    // activate it
    Component p = m.createComponent().setInterface(Service.class.getName(), null).setImplementation(provider);
    Client consumer = new Client(e);
    Component c = m.createComponent().setImplementation(consumer).add(m.createServiceDependency().setService(Service.class).setRequired(true));
    m.add(p);
    m.add(c);
    e.waitForStep(1, 5000);
    m.remove(p);
    e.waitForStep(2, 5000);
    m.remove(c);
    m.clear();
    // Make sure our static custom index has been used
    Assert.assertTrue(Boolean.getBoolean(OPENED));
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component)

Example 64 with Component

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

the class TestBase method setUp.

public void setUp() throws Exception {
    warn("Setting up test " + getClass().getName());
    context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
    Hashtable<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
    logService = context.registerService(LogService.class.getName(), this, props);
    context.addFrameworkListener(this);
    m_dm = new DependencyManager(context);
    if (m_parallel) {
        warn("Using threadpool ...");
        m_threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors());
        m_componentExecutorFactoryReg = context.registerService(ComponentExecutorFactory.class.getName(), new ComponentExecutorFactory() {

            @Override
            public Executor getExecutorFor(Component component) {
                return m_threadPool;
            }
        }, null);
    }
}
Also used : Hashtable(java.util.Hashtable) ComponentExecutorFactory(org.apache.felix.dm.ComponentExecutorFactory) DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 65 with Component

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

the class AbstractServiceDependencyTest method testAbstractClassDependency.

public void testAbstractClassDependency() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component sp = m.createComponent().setInterface(ServiceAbstract.class.getName(), null).setImplementation(new ServiceProvider(e));
    Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceAbstract.class).setRequired(true).setCallbacks("bind", "unbind"));
    m.add(sp);
    m.add(sc);
    m.remove(sp);
    // ensure we executed all steps inside the component instance
    e.step(8);
    m.clear();
}
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