felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chetan Mehrotra <chetan.mehro...@gmail.com>
Subject Re: Dynamically referencing a Service using Felix annotations
Date Wed, 26 Sep 2012 05:44:40 GMT
You can use dynamic references
@Component(...,specVersion="1.1")
@References({
        @Reference(
                name = "CheckReference",
                referenceInterface = CheckReference.class,
                cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE,
                policy = ReferencePolicy.DYNAMIC)
})
public class LoadReference {

And then have bind methods like

private Map<String,CheckReference> references = new
ConcurrentHashmap<String,CheckReference>()

private void bindCheckReference(CheckReference ref,Map config) {
        String domain = (String)config.get("domain");
        references.put(domain,ref);
}

private void unbindCheckReference(CheckReference ref,Map config) {
        String domain = (String)config.get("domain");
        references.remove(domain);

}


And then in your implementation lookup the appropriate impl from the
references map

Chetan Mehrotra

Mime
View raw message