[ 
https://issues.apache.org/jira/browse/FELIX-4426?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14165618#comment-14165618
 ] 

Pierre De Rop edited comment on FELIX-4426 at 10/9/14 7:37 PM:
---------------------------------------------------------------

Committed some improvements in rv 1630561: 

- You can now inject dependencies on a field with a Iterable<> type, and the 
field can optionally be final and already instantiated to an Iterable of your 
choice (this avoids to use volatile, and may improve performance):

For example:

{code}
public class SpellChecker {
    final Iterable<DictionaryService> m_dictionaries = new 
ConcurrentLinkedQueue<>();
    ...
}
{code}

- if the field type is "Iterable<>", and if you don't instantiate it (leaving 
it to null, and it is then assumed that you are using a volatile to ensure safe 
object publication), then a ConcurrentLinkedQueue will be automatically 
instantiated by DependencyManager. 
For example:

{code}
public class SpellChecker {
    volatile Iterable<DictionaryService> m_dictionaries = null; // will be 
instantiated by DM with a ConcurrentLnkedQueue.
    ...
}
{code}

Notice that when using annotations, it is not currently easily possible to 
detect the generic parameter type of the Iterable.
So, for now, if you are using annotations, you have to specify the type of the 
service dependency, using the "service" attribute:

{code}
@Component
public class SpellChecker {
    @ServiceDependency(service=DictionaryService.class)
    final Iterable<DictionaryService> m_dictionaries = new 
ConcurrentLinkedQueue<>();
    ...
}
{code}

In the future, it would be nice if the service dependency could be 
automatically detected from the Iterable parameter. For now, it's difficult to 
implement ... So for now, I prefer to spend time on trying to finish the DM4 
version.


was (Author: pderop):
Committed some improvements in rv 1630561: 

- You can now inject dependencies on a field with a Iterable<> type, and the 
field can optionally be final and already implemented to an Iterable of your 
choice (this avoids to use volatile, and may improve performance):

For example:

{code}
public class SpellChecker {
    final Iterable<DictionaryService> m_dictionaries = new 
ConcurrentLinkedQueue<>();
    ...
}
{code}

- if the field type is "Iterable<>", and if you don't instantiate it (leaving 
it to null, and it is then assumed that you are using a volatile to ensure safe 
object publication), then a ConcurrentLinkedQueue will be automatically 
instantiated by DependencyManager. 
For example:

{code}
public class SpellChecker {
    volatile Iterable<DictionaryService> m_dictionaries = null; // will be 
instantiated by DM with a ConcurrentLnkedQueue.
    ...
}
{code}

Notice that when using annotations, it is not currently easily possible to 
detect the generic parameter type of the Iterable.
So, for now, if you are using annotations, you have to specify the type of the 
service dependency, using the "service" attribute:

{code}
@Component
public class SpellChecker {
    @ServiceDependency(service=DictionaryService.class)
    final Iterable<DictionaryService> m_dictionaries = new 
ConcurrentLinkedQueue<>();
    ...
}
{code}

In the future, it would be nice if the service dependency could be 
automatically detected from the Iterable parameter. For now, it's difficult to 
implement ... So for now, I prefer to spend time on trying to finish the DM4 
version.

> Allow DM to manage collections of services
> ------------------------------------------
>
>                 Key: FELIX-4426
>                 URL: https://issues.apache.org/jira/browse/FELIX-4426
>             Project: Felix
>          Issue Type: New Feature
>          Components: Dependency Manager
>    Affects Versions: dependencymanager-4.0.0
>            Reporter: J.W. Janssen
>            Assignee: Pierre De Rop
>             Fix For: dependencymanager-4.0.0
>
>
> DM has great support for single-cardinality dependencies, allowing you to 
> only declare the dependency as (volatile) field. For multiple-cardinality 
> dependencies, no such support is present, forcing you to always manually 
> implement this using callbacks.
> It would be great if I could declare multiple-cardinality dependencies like:
> {code}
> private volatile List<MyService> m_services;
> {code}
> and let DM manage the list for me.
> Note that you need some additional reflection mojo to obtain the actual 
> collection type. An example of how this can work can be found in a utility 
> class for Swagger in the Amdatu-Web project, see 
> https://bitbucket.org/amdatu/amdatu-web/src/master/org.amdatu.web.rest/src/org/amdatu/web/rest/doc/swagger/SwaggerUtil.java?at=master#cl-304



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

Reply via email to