Package org.apache.felix.dm

Examples of org.apache.felix.dm.DependencyManager.createComponent()


    public void testDynamicallyAddAndRemoveAspect() {
        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(ServiceInterface2.class.getName(), null);
        Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
        Component aspect = m.createAspectService(ServiceInterface.class, null, 1, null).setImplementation(new ServiceAspect(e));
       
        m.add(consumer);
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 and consumer
        Component provider = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
        Component provider2 = m.createComponent().setImplementation(new ServiceProvider2(e)).setInterface(ServiceInterface2.class.getName(), null);
        Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
        Component aspect = m.createAspectService(ServiceInterface.class, null, 1, null).setImplementation(new ServiceAspect(e));
       
        m.add(consumer);
        m.add(provider);
View Full Code Here

        // 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(ServiceInterface2.class.getName(), null);
        Component consumer = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
        Component aspect = m.createAspectService(ServiceInterface.class, null, 1, null).setImplementation(new ServiceAspect(e));
       
        m.add(consumer);
        m.add(provider);
        // the consumer should invoke the provider here, and when done, arrive at step 3
View Full Code Here

        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a resource provider
        ResourceProvider provider = new ResourceProvider(e);
        // activate it
        m.add(m.createComponent().setImplementation(provider).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add", "remove")));
        // 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
        m.add(m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, null, "changed")
              .setImplementation(new ResourceAdapter(e)));
View Full Code Here

    @Test
    public void testServiceDependencyPropagate() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        Component c1 = m.createComponent()
                      .setImplementation(new C1(e))
                      .add(m.createServiceDependency().setService(C2.class).setRequired(true).setCallbacks("bind", null));

        Component c2 = m.createComponent()
                      .setInterface(C2.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
View Full Code Here

        Ensure e = new Ensure();
        Component c1 = m.createComponent()
                      .setImplementation(new C1(e))
                      .add(m.createServiceDependency().setService(C2.class).setRequired(true).setCallbacks("bind", null));

        Component c2 = m.createComponent()
                      .setInterface(C2.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
                      .setImplementation(new C2())
                      .add(m.createServiceDependency().setService(C3.class).setRequired(true).setPropagate(true));

        Component c3 = m.createComponent()
View Full Code Here

        Component c2 = m.createComponent()
                      .setInterface(C2.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
                      .setImplementation(new C2())
                      .add(m.createServiceDependency().setService(C3.class).setRequired(true).setPropagate(true));

        Component c3 = m.createComponent()
                      .setInterface(C3.class.getName(), new Hashtable() {{ put("foo2", "bar2"); }})
                      .setImplementation(new C3());
       
        m.add(c1);
        m.add(c2);
View Full Code Here

    private void invokeTest(BundleContext context, int numberOfServices) {
        DependencyManager m = new DependencyManager(context);
        // create a number of services
    for (int i = 0; i < numberOfServices; i++) {
      final int num = i;
      m.add(m.createComponent()
          .setInterface(Service.class.getName(), null)
          .setImplementation(new Service() {
              public String toString() {
                  return "A" + num;
                  }
View Full Code Here

        );
    }

    // create a service with dependency which will be invoked on a callback instance
    CallbackInstance instance = new CallbackInstance();
    m.add(m.createComponent()
        .setImplementation(new SimpleService() {})
        .add(m.createServiceDependency()
        .setService(Service.class)
        .setCallbacks(instance, "added", "removed")
        .setRequired(true)
View Full Code Here

        int count = 100;
        for (int i = 0; i < count; i++) {
          // create a service provider and consumer
          Dictionary props = new Hashtable();
          props.put("number", "" + i);
          Component original = m.createComponent()
              .setImplementation(new ServiceProvider("" + i, e))
              .setInterface(OriginalService.class.getName(), props);
         
          Component consumer = m.createComponent()
              .setImplementation(new ServiceConsumer(e, "" + i))
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.