felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pierre De Rop (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (FELIX-4426) Allow DM to manage collections of services
Date Tue, 30 Sep 2014 20:50:34 GMT

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

Pierre De Rop resolved FELIX-4426.
       Resolution: Fixed
    Fix Version/s: dependencymanager-4.0.0

I committed in revision 1628547 this interesting new feature in DM 4 (currently in my sandbox),
including a test case (org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/AutoConfigTest.java).

Now, you can define an auto config dependency on a field which type can be either a Collection
parameterized with the service dependency type, or a Map<ServiceDependency class, Dictionary>

The Collection can be simply used to iterate whenever you want on the currently available
service dependencies, and the map can be used to also get access to the properties of the
service dependency.

For example, to iterate on the available dependencies (safely), you can use a ConcurrentLinkedQueue
(it is thread safe, and very efficient if many service dependencies are injected):

    public class ConsumerCollection {
        volatile ConcurrentLinkedQueue<MyService> services;
        void start() {
            for (MyService service : services) {

And to get access to the injected services, and to their service properties, you can then
use a ConcurrentHashMap:

    public class ConsumerMap {
        volatile ConcurrentHashMap<MyService, Dictionary> services;
        void start() {
            for (Map.Entry<MyService, Dictionary> entry : services.entrySet()) {
                System.out.println("myService=" + entry.getKey());
                System.out.println("myService properties="  + entry.getValue());

I think the issue is resolved, but reopen it if you disagree.

> 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

View raw message