You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Pierre De Rop (JIRA)" <ji...@apache.org> on 2015/03/01 15:16:04 UTC

[jira] [Updated] (FELIX-4684) Replace DependencyManager Runtime "factorySet" by a cleaner API

     [ https://issues.apache.org/jira/browse/FELIX-4684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop updated FELIX-4684:
---------------------------------
    Component/s:     (was: Dependency Manager)
                 Dependency Manager Runtime
                 Dependency Manager Annotations

> Replace DependencyManager Runtime "factorySet" by a cleaner API
> ---------------------------------------------------------------
>
>                 Key: FELIX-4684
>                 URL: https://issues.apache.org/jira/browse/FELIX-4684
>             Project: Felix
>          Issue Type: Wish
>          Components: Dependency Manager Annotations, Dependency Manager Runtime
>    Affects Versions: dependencymanager.annotations-3.2.0, dependencymanager.runtime-3.2.0
>            Reporter: Pierre De Rop
>            Assignee: Pierre De Rop
>            Priority: Minor
>             Fix For: org.apache.felix.dependencymanager-r1
>
>
> 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:
> {code}
> @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;
>     }
> }
> {code}
> and the above component could then be instantiated multiple times like this:
> {code}
> @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);    
>     }    
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)