[ https://issues.apache.org/jira/browse/FELIX-5139?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15056330#comment-15056330 ]
Carsten Ziegeler commented on FELIX-5139: ----------------------------------------- [~olli] I don't know any documentation for this, and the spec is just generally describing it. One reason for this is to make the spec simply, otherwise you have to describe and list all these cases and how they are handled. Real use cases might be rare, however you can combine getting the field set and an event (through the methods) to react on the change of the field. For references of multiple cardinality this might be handy as DS does the aggregation and sorting for you, sets the field and then calls the bind method to notify you of the change. You could also path in different obejcts for your reference, let the field use a service reference, pass in the properties through the event method etc. > SCR logs errors for reference but works as expected > --------------------------------------------------- > > Key: FELIX-5139 > URL: https://issues.apache.org/jira/browse/FELIX-5139 > Project: Felix > Issue Type: Bug > Components: Declarative Services (SCR), Maven Bundle Plugin > Affects Versions: scr-2.0.2, maven-bundle-plugin-3.0.1 > Reporter: Oliver Lietz > > When annotating a field like below with {{bind}} and {{unbind}} I don't > expect SCR to act on the field directly but using named {{bind}} and > {{unbind}} methods instead (which is the case indeed). > {noformat} > @Reference( > service = FooService.class, > cardinality = ReferenceCardinality.AT_LEAST_ONE, > policy = ReferencePolicy.DYNAMIC, > bind = "addFooService", > unbind = "removeFooService" > ) > private final Set<FooService> fooServices = new > LinkedHashSet<FooService>(); > protected synchronized void addFooService(final FooService fooService) { > fooServices.add(fooService); > // operate on fooServices > } > protected synchronized void removeFooService(final FooService fooService) > { > fooServices.remove(fooService); > // operate on fooServices > } > {noformat} > Nevertheless SCR logs errors at runtime when binding services: > {noformat} > [...] | ERROR | xFrameworkWiring | [...] | [[...]] Field fooServices in > component class [...] must be declared volatile to handle a dynamic reference > [...] | ERROR | xFrameworkWiring | [...] | [[...]] Field fooServices in > component class [...] has unsupported type java.util.Set. It must be one of > java.util.Collection or java.util.List. > [...] | ERROR | xFrameworkWiring | [...] | [[...]] Field fooServices in > component class [...] must not be declared as final > {noformat} > The reference in SCR Component descriptor contains the attribute {{field}} > (which is likely the cause for the errors): > {noformat} > <reference name="fooServices" cardinality="1..n" policy="dynamic" > interface="FooService" bind="addFooService" unbind="removeFooService" > field="fooServices"/> > {noformat} > If the combination of reference attributes as above is illegal, Maven Bundle > Plugin should log the errors at compile time instead and break the build. -- This message was sent by Atlassian JIRA (v6.3.4#6332)