Method call of OSGi components which implements the same interface | Community
Skip to main content
Level 2
May 1, 2017
Solved

Method call of OSGi components which implements the same interface

  • May 1, 2017
  • 2 replies
  • 903 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by 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 replies

smacdonald2008
smacdonald2008Accepted solution
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