[
https://issues.apache.org/jira/browse/FELIX-4684?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Pierre De Rop updated FELIX-4684:
---------------------------------
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:
{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}
was:
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 mutliple times like this:
{code}
@Component
public class DeviceFactory {
@ServiceDependency(filter = "(" + ComponentFactory.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}
> 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
> Affects Versions: dependencymanager.annotations-3.2.0,
> dependencymanager.runtime-3.2.0
> Reporter: Pierre De Rop
> Assignee: Pierre De Rop
> Priority: Minor
> Fix For: dependencymanager.annotations-4.0.0,
> dependencymanager.runtime-4.0.0
>
>
> 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)