Package org.apache.felix.dm

Examples of org.apache.felix.dm.Component


   public void testReplacementCallbacks() {
       DependencyManager m = new DependencyManager(context);
       // helper class that ensures certain steps get executed in sequence
       Ensure e = new Ensure();
       // create a service provider and consumer
       Component provider = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
       Component provider2 = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(), null);
       Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e))
         .add(m.createServiceDependency()
              .setService(ServiceInterface.class)
              .setRequired(true)
              .setCallbacks("add", "remove"));
       m.add(provider2);
View Full Code Here


    public void testMultipleExtraDependencies()
    {
        DependencyManager m = new DependencyManager(context);
        Ensure e = new Ensure();
       
        Component sp2 = m.createComponent()
              .setImplementation(ServiceProvider2.class).setInterface(ServiceProvider2.class.getName(), null)
              .add(m.createServiceDependency()
                   .setService(Runnable.class, "(foo=bar)")
                   .setRequired(false)
                   .setAutoConfig("m_runnable"))
              .add(m.createServiceDependency()
                   .setService(Sequencer.class)
                   .setRequired(true)
                   .setCallbacks("bind", null))
              .setCallbacks(null, "start", "stop", null)
              .setComposition("getComposition");
       
        Component sp = m.createComponent()
              .setImplementation(ServiceProvider.class)
              .setInterface(ServiceInterface.class.getName(),
                            new Hashtable() {{ put("foo", "bar"); }})
              .add(m.createServiceDependency()
                   .setService(Sequencer.class)
                   .setRequired(true)
                   .setAutoConfig("m_sequencer"))
               .add(m.createServiceDependency()
                   .setService(ServiceProvider2.class)
                   .setRequired(true)
                   .setCallbacks("bind", "unbind"))
              .setCallbacks(null, "start", "stop", null);
       
        Component sc = m.createComponent()
              .setImplementation(ServiceConsumer.class)
              .add(m.createServiceDependency()
                   .setService(Sequencer.class)
                   .setRequired(true)
                   .setAutoConfig("m_sequencer"))
               .add(m.createServiceDependency()
                   .setService(ServiceInterface.class, "(foo=bar)")
                   .setRequired(true)
                   .setAutoConfig("m_service"))
              .setCallbacks(null, "start", "stop", null);
       
        // Provide the Sequencer service to the MultipleAnnotationsTest class.
        Component sequencer =
            m.createComponent().setImplementation(new SequencerImpl(e))
                             .setInterface(Sequencer.class.getName(), null);
        m.add(sp2);
        m.add(sp);
        m.add(sc);
View Full Code Here

    public void testInstanceBoundDependency() {
        DependencyManager m = new DependencyManager(context);
        // 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(ServiceInterface.class.getName(), null)
            .setImplementation(new ServiceProvider(e));
        Component sp2 = m.createComponent()
        .setInterface(ServiceInterface2.class.getName(), null)
            .setImplementation(new ServiceProvider2(e));
        Component sc = m.createComponent()
            .setImplementation(new ServiceConsumer())
            .add(m.createServiceDependency()
                .setService(ServiceInterface3.class)
                .setRequired(true));
        Component sa = m.createAdapterService(ServiceInterface.class, null)
            .setInterface(ServiceInterface3.class.getName(), null)
            .setImplementation(new ServiceAdapter(e));
        m.add(sc);
        m.add(sp);
        m.add(sp2);
View Full Code Here

        Ensure e = new Ensure();
       
        // create a service provider and consumer
        ServiceProvider p = new ServiceProvider(e, "a");
        ServiceConsumer c = new ServiceConsumer(e);
        Component sp = m.createComponent()
            .setInterface(ServiceInterface.class.getName(), new Properties() {{ put("name", "a"); }})
            .setImplementation(p);
        Component sc = m.createComponent()
            .setImplementation(c)
            .add(m.createServiceDependency()
                .setService(ServiceInterface.class)
                .setRequired(true)
                .setCallbacks("add", "remove")
                .setAutoConfig(true)
            );
        Component sa = m.createAspectService(ServiceInterface.class, null, 20, null)
            .setImplementation(ServiceAspect.class);
        m.add(sc);
        m.add(sp);
        // after the provider was added, the consumer's add should have been invoked once
        e.waitForStep(1, 2000);
View Full Code Here

        Ensure e = new Ensure();
       
        // create a service provider and consumer
        ServiceProvider p = new ServiceProvider(e, "a");
        ServiceConsumer c = new ServiceConsumer(e);
        Component sp = m.createComponent().setImplementation(p).setInterface(ServiceInterface.class.getName(), new Properties() {{ put("name", "a"); }});
        Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove").setAutoConfig(true));
        Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
        // we first add the aspect
        m.add(sa);
        // then the service provider
        m.add(sp);
        // finally the consumer
View Full Code Here

        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
       
        // create service providers and consumers
        ServiceConsumer c = new ServiceConsumer(e);
        Component sp = m.createComponent().setImplementation(new ServiceProvider(e, "a")).setInterface(ServiceInterface.class.getName(), new Properties() {{ put("name", "a"); }});
        Component sp2 = m.createComponent().setImplementation(new ServiceProvider(e, "b")).setInterface(ServiceInterface.class.getName(), new Properties() {{ put("name", "b"); }});
        Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove"));
        Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
        Component sa2 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(ServiceAspect.class);
        m.add(sp);
        m.add(sp2);
        m.add(sa);
        m.add(sa2);
        m.add(sc);
View Full Code Here

    public void testBuildAspectChain() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a service provider and consumer
        Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
        Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
        Component sa2 = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(new ServiceAspect(e, 3));
        Component sa3 = m.createAspectService(ServiceInterface.class, null, 30, null).setImplementation(new ServiceAspect(e, 2));
        Component sa1 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(new ServiceAspect(e, 4));
        m.add(sc);

        m.add(sp);
        m.add(sa2);
        m.add(sa3);
View Full Code Here

    public void testServiceRegistrationAndConsumption() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a service provider and consumer
        Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
        Component sc = m.createComponent().setImplementation(new ServiceConsumerCallbacks(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(false).setCallbacks("add", "change", "remove", "swap"));
        Component asp = m.createAspectService(ServiceInterface.class, null, 1000, null).setImplementation(ServiceProviderAspect.class);
        m.add(sp);
        m.add(sc);
        m.add(asp);       
        m.remove(sc);
        m.remove(sp);
View Full Code Here

            while (iterator.hasNext()) {
                DependencyManager manager = iterator.next();
                List<Component> complist = manager.getComponents();
                Iterator<Component> componentIterator = complist.iterator();
                while (componentIterator.hasNext()) {
                    Component component = componentIterator.next();
                    ComponentDeclaration sc = (ComponentDeclaration) component;
                    String name = sc.getName();
                    // check if this component is enabled or disabled.
                    if (!mayDisplay(component, servicesFilter, componentsRegex, cids)) {
                        continue;
View Full Code Here

        // create a resource adapter for our single resource
        // note that we can provide an actual implementation instance here because there will be only one
        // adapter, normally you'd want to specify a Class here
        ResourceAdapter service = new ResourceAdapter(e);
        CallbackInstance callbackInstance = new CallbackInstance(e);
        Component component = m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, callbackInstance, "changed")
            .setImplementation(new ResourceAdapter(e))
            .setCallbacks(callbackInstance, "init", "start", "stop", "destroy")
            .add(m.createServiceDependency()
            .setService(ServiceInterface.class, "(id=1)")
            .setRequired(true)
            .setInstanceBound(true)
        );
        component.addStateListener(new ComponentStateListenerImpl(e));
        m.add(component);
        // wait until the single resource is available
        e.waitForStep(1, 5000);
        // trigger a 'change' in our resource
        provider.change();
View Full Code Here

TOP

Related Classes of org.apache.felix.dm.Component

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.