Package org.apache.felix.dm

Examples of org.apache.felix.dm.Component


        m_invokeStep = new Ensure();
       
        // Create our original "S" service.
        Dictionary props = new Hashtable();
        props.put("foo", "bar");
        Component s = m.createComponent()
                .setImplementation(new SImpl())
                .setInterface(S.class.getName(), props);
       
        // Create an aspect aware client, depending on "S" service.
        Client clientImpl;
        Component client = m.createComponent()
                .setImplementation((clientImpl = new Client()))
                .add(m.createServiceDependency()
                     .setService(S.class)
                     .setRequired(true)
                     .setDebug("client")
View Full Code Here


        m_invokeStep = new Ensure();
       
        // Create our original "S" service.
        Dictionary props = new Hashtable();
        props.put("foo", "bar");
        Component s = m.createComponent()
                .setImplementation(new SImpl())
                .setInterface(S.class.getName(), props);
       
        // Create an aspect aware client, depending on "S" service.
        Client clientImpl;
        Component client = m.createComponent()
                .setImplementation((clientImpl = new Client()))
                .add(m.createServiceDependency()
                     .setService(S.class)
                     .setRequired(true)
                     .setDebug("client")
View Full Code Here

        m_invokeStep = new Ensure();
       
        // Create our original "S" service.
        Dictionary props = new Hashtable();
        props.put("foo", "bar");
        Component s = m.createComponent()
                .setImplementation(new SImpl())
                .setInterface(S.class.getName(), props);
       
        // Create some "S" aspects
        Component[] aspects = new Component[ASPECTS];
        for (int rank = 1; rank <= ASPECTS; rank ++) {
            aspects[rank-1] = m.createAspectService(S.class, null, rank, "add", "change", "remove", "swap")
                    .setImplementation(new A("A" + rank, rank));
            props = new Hashtable();
            props.put("a" + rank, "v" + rank);
            aspects[rank-1].setServiceProperties(props);
        }
       
        // Create S2 adapter (which adapts S1 to S2 interface)
        Component adapter = m.createAdapterService(S.class, null, "add", "change", "remove", "swap")
                .setInterface(S2.class.getName(), null)
                .setImplementation(new S2Impl());
       
        // Create Client2, which depends on "S2" service.
        Client2 client2Impl;
        Component client2 = m.createComponent()
                .setImplementation((client2Impl = new Client2()))
                .add(m.createServiceDependency()
                     .setService(S2.class)
                     .setRequired(true)
                     .setDebug("client")                    
View Full Code Here

        m_invokeStep = new Ensure();
       
        // Create our original "S" service.
        Dictionary props = new Hashtable();
        props.put("foo", "bar");
        Component s = m.createComponent()
                .setImplementation(new SImpl())
                .setInterface(S.class.getName(), props);
       
        // Create some "S" aspects
        Component[] aspects = new Component[ASPECTS];
        for (int rank = 1; rank <= ASPECTS; rank ++) {
            aspects[rank-1] = m.createAspectService(S.class, null, rank)
                    .setImplementation(new A("A" + rank, rank));
            props = new Hashtable();
            props.put("a" + rank, "v" + rank);
            aspects[rank-1].setServiceProperties(props);
        }
       
        // Create S2 adapter (which adapts S1 to S2 interface)
        Component adapter = m.createAdapterService(S.class, null)
                .setInterface(S2.class.getName(), null)
                .setImplementation(new S2Impl());
       
        // Create Client2, which depends on "S2" service.
        Client2 client2Impl;
        Component client2 = m.createComponent()
                .setImplementation((client2Impl = new Client2()))
                .add(m.createServiceDependency()
                     .setService(S2.class)
                     .setRequired(true)
                     .setDebug("client")                    
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)
            .setCallbacks("init", "start", "stop", null)
            .setComposition("getComposition");
       
        Component sp = m.createComponent()
              .setImplementation(ServiceProvider.class)
              .setInterface(ServiceInterface.class.getName(), new Hashtable() {{ put("foo", "bar"); }})                           
              .setCallbacks("init", "start", "stop", null);
       
        Component sc = m.createComponent()
              .setImplementation(ServiceConsumer.class)
              .setCallbacks("init", "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 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 ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
        Component sc2 = m.createComponent().setImplementation(new ServiceConsumerCallbacks(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(false).setCallbacks("add", "remove"));
        m.add(sp);
        m.add(sc);
        m.remove(sc);
        m.add(sc2);
        m.remove(sp);
View Full Code Here

        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
       
        // create two service providers, each providing a different service interface
        Component sp1 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
        Component sp2 = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface2.class.getName(), null);
       
        // create a dynamic proxy based aspect and hook it up to both services
        Component a1 = m.createAspectService(ServiceInterface.class, null, 10, "m_service")
            .setFactory(new Factory(e, ServiceInterface.class, "ServiceInterfaceProxy"), "create");
        Component a2 = m.createAspectService(ServiceInterface2.class, null, 10, "m_service")
            .setFactory(new Factory(e, ServiceInterface2.class, "ServiceInterfaceProxy2"), "create");

        // create a client that invokes a method on boths services, validate that it goes
        // through the proxy twice
        Component sc = m.createComponent()
            .setImplementation(new ServiceConsumer(e))
            .add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true))
            .add(m.createServiceDependency().setService(ServiceInterface2.class).setRequired(true))
            ;
       
View Full Code Here

        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
       
        // create a service provider
        Component provider = m.createComponent()
            .setImplementation(new ServiceProvider())
            .setInterface(OriginalService.class.getName(), null);

        // create a adapter on the provider
        Component adapter = m.createAdapterService(OriginalService.class, null)
        .setInterface(AdaptedService.class.getName(), null)
        .setImplementation(ServiceAdapter.class);
       
        // create a consumer for the adapted service
        Component consumer = m.createComponent()
            .setImplementation(new ServiceConsumer(e))
            .add(m.createServiceDependency()
                .setService(AdaptedService.class)
                .setCallbacks("add", "remove")
                .setRequired(true)
            );
       
        // create an aspect on the service provider
        Component aspect = m.createAspectService(OriginalService.class, null, 10, null)
            .setImplementation(ServiceAspect.class);

        // we first start the provider, the adapter and the consumer
        m.add(provider);
        m.add(adapter);
View Full Code Here

   public void testMultipleServiceRegistrationAndConsumption() {
       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 providerWithHighRank = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface.class.getName(), new Properties() {{ put(Constants.SERVICE_RANKING, Integer.valueOf(5)); }});
       Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
       m.add(provider);
       m.add(providerWithHighRank);
       m.add(consumer);
       e.waitForStep(3, 15000);
       m.remove(providerWithHighRank);
View Full Code Here

   public void testReplacementAutoConfig() {
       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));
       m.add(provider2);
       m.add(consumer);
       e.waitForStep(3, 15000);
       m.add(provider);
       m.remove(provider2);
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.