Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-4684

Replace DependencyManager Runtime "factorySet" by a cleaner API

    XMLWordPrintableJSON

Details

    Description

      When using DependencyManager annotations, there is the ability to create component instances using "factory sets", which are similar to the (beautiful) Declarative Service component factories, except that instead of providing in the OSGI registry a clean interface like org.osgi.service.component.ComponentFactory, a "java.util.Set" object is registered and when you add a dictionary in the Set, a corresponding component instance is created.

      whilst using a java.util.Set allows to prevent application to depend on a specific API, it turns out that using a Set as a factory for objects is counterintuitive , and when you read a code which depends on a java.util.Set object, the code is difficult to understand. Moreover, you can't assign a version to the java.util package.

      So, this issue is about to just simply replace the java.util.Set with a nice and simple interface which would be exported by the DM runtime bundle. For sake of clarity, we can use the same interface names as declarative service: ComponentFactory with a nice "newInstance(Dictionary)" method which returns some ComponentInstances.
      And from the @Component annotation, a new "factorySet" attribute can be used instead of the factorySet one;

      That would give:

      @Component(factoryName = "Device", factoryConfigure = "configure")
      public class DeviceImpl implements Device {
          int id;
      
          void configure(Dictionary<String, Object> configuration) {
              this.id = (Integer) configuration.get("device.id");
          }
      
          @Override
          public int getDeviceId() {
              return id;
          }
      }
      

      and the above component could then be instantiated multiple times like this:

      @Component
      public class DeviceFactory {
          @ServiceDependency(filter = "(" + Component.FACTORY_NAME + "=Device)")
          volatile ComponentFactory m_deviceFactory;
              
          private ComponentInstance createDevice(int id) {
              // create a Device service
              Dictionary<String,Object> device = new Hashtable<>();
              device.put("device.id", new Integer(id));
              return m_deviceFactory.newInstance(device);    
          }    
      }
      

      Attachments

        Activity

          People

            pderop Pierre De Rop
            pderop Pierre De Rop
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: