Search in sources :

Example 51 with DependencyManager

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

the class MultipleExtraDependencyTest method testMultipleExtraDependencies.

public void testMultipleExtraDependencies() {
    DependencyManager m = getDM();
    Ensure e = new Ensure();
    Component sp2 = component(m).impl(ServiceProvider2.class).provides(ServiceProvider2.class).withSvc(Runnable.class, srv -> srv.filter("(foo=bar)").required(false).autoConfig("m_runnable")).withSvc(Sequencer.class, srv -> srv.add("bind")).composition("getComposition").build();
    Component sp = component(m).impl(ServiceProvider.class).provides(ServiceInterface.class, foo -> "bar").start("start").stop("stop").withSvc(Sequencer.class, srv -> srv.autoConfig("m_sequencer")).withSvc(ServiceProvider2.class, srv -> srv.add("bind").remove("unbind")).build();
    Component sc = component(m).impl(ServiceConsumer.class).start("start").stop("stop").withSvc(Sequencer.class, srv -> srv.autoConfig("m_sequencer")).withSvc(ServiceInterface.class, srv -> srv.filter("(foo=bar)").autoConfig("m_service")).build();
    Component sequencer = component(m).impl(new SequencerImpl(e)).provides(Sequencer.class.getName()).build();
    m.add(sp2);
    m.add(sp);
    m.add(sc);
    m.add(sequencer);
    // Check if ServiceProvider component have been initialized orderly
    e.waitForStep(7, 5000);
    // Stop the test.annotation bundle
    m.remove(sequencer);
    m.remove(sp);
    m.remove(sp2);
    m.remove(sc);
    // And check if ServiceProvider2 has been deactivated orderly
    e.waitForStep(11, 5000);
}
Also used : Component(org.apache.felix.dm.Component) 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 52 with DependencyManager

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

the class MultipleServiceDependencyTest method testMultipleServiceRegistrationAndConsumption.

public void testMultipleServiceRegistrationAndConsumption() {
    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 providerWithHighRank = component(m).impl(new ServiceProvider2(e)).provides(ServiceInterface.class.getName(), Constants.SERVICE_RANKING, Integer.valueOf(5)).build();
    Component consumer = component(m).impl(new ServiceConsumer(e)).withSvc(ServiceInterface.class, true).build();
    m.add(provider);
    m.add(providerWithHighRank);
    m.add(consumer);
    e.waitForStep(3, 5000);
    m.remove(providerWithHighRank);
    e.step(4);
    e.waitForStep(5, 5000);
    m.remove(provider);
    m.remove(consumer);
    e.waitForStep(6, 5000);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component)

Example 53 with DependencyManager

use of org.apache.felix.dm.DependencyManager 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 54 with DependencyManager

use of org.apache.felix.dm.DependencyManager 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 55 with DependencyManager

use of org.apache.felix.dm.DependencyManager 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)

Aggregations

DependencyManager (org.apache.felix.dm.DependencyManager)255 Component (org.apache.felix.dm.Component)226 Ensure (org.apache.felix.dm.itest.util.Ensure)91 DependencyManagerActivator.component (org.apache.felix.dm.lambda.DependencyManagerActivator.component)70 Hashtable (java.util.Hashtable)56 Assert (org.junit.Assert)50 Dictionary (java.util.Dictionary)28 Map (java.util.Map)27 ServiceReference (org.osgi.framework.ServiceReference)24 DependencyManagerActivator.aspect (org.apache.felix.dm.lambda.DependencyManagerActivator.aspect)21 ServiceRegistration (org.osgi.framework.ServiceRegistration)18 DependencyManagerActivator.adapter (org.apache.felix.dm.lambda.DependencyManagerActivator.adapter)15 Bundle (org.osgi.framework.Bundle)15 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 ComponentDeclaration (org.apache.felix.dm.ComponentDeclaration)12 ServiceDependency (org.apache.felix.dm.ServiceDependency)11 Properties (java.util.Properties)10 List (java.util.List)9 DependencyGraph (org.apache.felix.dm.diagnostics.DependencyGraph)9