Method call of OSGi components which implements the same interface | Adobe Higher Education
Skip to main content
Level 2
May 1, 2017
Répondu

Method call of OSGi components which implements the same interface

Hi,

I have two OSGI Component classes with implementing the same interface.

Class WordsValidatorImpl implements ContentValidators {

    void validate() {}
}
Class ActivationValidatorImpl implements ContentValidators {
    void validate() {}
}

I need call the validate() method on both the classes. How to do that?

@Reference ContentValidators contentValidators;

If I call contentValidators.validate() only method in one component is getting called, instead of two. 

thanks

Srini

Ce sujet a été fermé aux réponses.
Meilleure réponse par smacdonald2008

See this article - it will show you what to do. 

http://scottsdigitalcommunity.blogspot.ca/2017/03/managing-adobe-experience-manager-osgi.html

You need to use target - as discussed in that article. 

2 commentaires

smacdonald2008
Level 10
May 1, 2017

See this article - it will show you what to do. 

http://scottsdigitalcommunity.blogspot.ca/2017/03/managing-adobe-experience-manager-osgi.html

You need to use target - as discussed in that article. 

May 1, 2017

One way would be to create a contentValidatorManager service that keeps track of all the contentValidators as they are registered. Then instead of referencing contentValidators you reference contentValidatorsManager and call a new validatorAllValidators() that would loop through all registered validators.

References

http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html#reference

https://architectslog.wordpress.com/2013/02/18/multiple-cardinality-osgi-references-using-scr-annotations/

https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/adobe/acs/commons/httpcache/engine/impl/HttpCacheEngineImpl.java