karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xtra Coder <xtraco...@gmail.com>
Subject Re: @Reference(service = MyApi.class) is not re-populated
Date Fri, 08 Mar 2019 09:28:43 GMT
Your hints plus now looking into correct place of the OSGI spec bought me to
the solution which i was looking for (and it is different from the typical
CDI approach).

So ... for my scenario annotation should be actually attached to the setter
method (as I've found here
https://osgi.org/specification/osgi.cmpn/7.0.0/service.component.html#service.component-reference.element
-> sample about setLog).

Thanks for help. Here is sample for copy/paste.

    private final List<MyApi> implementations = new
CopyOnWriteArrayList<>();

    @Reference(service        = MyApi.class
               , cardinality  = ReferenceCardinality.MULTIPLE
               , policy       = ReferencePolicy.DYNAMIC
               , unbind       = "removeImpl"
               )
    private void setImpl(MyApi impl)    {
        System.out.println("---------------------------------------- +++++ =
" + instanceId + " + " + impl );
        implementations.add(impl); 
    }
    
    private void removeImpl(MyApi impl) {
        System.out.println("---------------------------------------- ----- =
" + instanceId + " - " + impl );
        implementations.remove(impl);
    }





--
Sent from: http://karaf.922171.n3.nabble.com/Karaf-User-f930749.html

Mime
View raw message