How can I distinguish between published OSGI services implementing same interface by their properties?
How can I distinguish between published OSGI services implementing same interface by their properties?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that you want to retrieve registered services based on certain values for properties, you need to use a filter (which is based on the LDAP syntax).
For example:
where you want to look for services both implementing
MyInterfaceand having a value of theportproperty equal tomyport.Here is the relevant javadoc for getting the references.
Remark 1:
The above example and javadoc refer to the Release 4.2. If you are not restricted to a J2SE 1.4 runtime, I suggest you to have a look at the Release 4.3 syntax, where you can use generics.
Remark 2: (courtesy of Ray)
You can also pre-check the correctness of your filter by instead creating a Filter object from a
filterStrstring:which also allows you to match the filter with other criteria. You still pass
filterStrto get the references, since there is no overloading that accounts for aFilterargument. Please be aware, however, that in this way you will check the correctness twice: bothgetServiceReferencesandcreateFilterthrowInvalidSyntaxExceptionon parsing the filter. Certainly not a show-stopper inefficiency, I guess, but it is worth mentioning.