Question

I am newbie in OSGi. I have googled about a few hours but couldn't find the answer. Maybe my understanding is wrong. So the problem. Lets suppose I have a component.

<component name="sample.component" immediate="true">
  <implementation class="sample.SampleComparator" />
  <service>
    <provide interface="java.util.Comparator" />
  </service>
</component>

and in code:

ServiceReference[] serviceReferences = 
    bundleContext.getServiceReferences(
        java.util.Comparator.class.getName(), "(name=sample.component)");

But I get null. Where is the mistake? Is filter (name=sample.component) right? Or how can I set id of the service and lookup by it?

Was it helpful?

Solution

The name of the service property is "component.name", not "name".

If you do this, it will work:

getServiceReferences(java.util.Comparator.class.getName(),"(component.name=sample.component)");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top