Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8114947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:18:34+00:00 2026-06-06T03:18:34+00:00

How can I distinguish between published OSGI services implementing same interface by their properties?

  • 0

How can I distinguish between published OSGI services implementing same interface by their properties?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:18:35+00:00Added an answer on June 6, 2026 at 3:18 am

    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:

    int myport = 5000;
    String filter = "&(objectClass=" + MyInterface.class.getName() 
                    + ")(port=" + myport + ")";
    ServiceReference[] serviceReferences = bundleContext.getServiceReferences(null,filter);
    

    where you want to look for services both implementing MyInterface and having a value of the port property equal to myport.

    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 filterStr string:

    Filter filter = bundleContext.createFilter(filterStr);  
    

    which also allows you to match the filter with other criteria. You still pass filterStr to get the references, since there is no overloading that accounts for a Filter argument. Please be aware, however, that in this way you will check the correctness twice: both getServiceReferences and createFilter throw InvalidSyntaxException on parsing the filter. Certainly not a show-stopper inefficiency, I guess, but it is worth mentioning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find a CSS selector that can help me distinguish between the
Can I distinguish signal, between delivered directly to a process and delivered via debugger.
Can somebody distinguish between a crawler and scraper in terms of scope and functionality.
How can I distinguish between None and False in django templates? {% if x
I wonder if someone can distinguish precisely between these? For my understanding, Core Graphics
using jquery, how can you distinguish between refreshing vs. navigating away from the current
I can not distinguish the difference between aggregating and holding. What does it mean
Can I distinguish between compiled application from VS2008 Professional and Express?
Using JavaScript, how can I distinguish between a left and right mouse button click
I need a javascript regex that can distinguish between PHP tags in HTML tags

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.