Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Method call of OSGi components which implements the same interface

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 10

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. 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

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. 

Avatar

Level 1

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...

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

https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/main/java/com/ad...