ServiceTracker sometimes misses services? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of ServiceTracker sometimes misses services? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have an OSGi service tracker with a filter. I noticed that there’s a service that it misses (‘addingService’ is not called). When I use the services command in my osgi (equinox) shell, with the filter that the tracker uses, the missed service is returned.

Answer

It turns out that in Equinox, the chain to ServiceTracker#addingService goes through a check BundleContextImpl#isAssignableTo with the reference to the service. This checks if the classes of the reference are wired for the same source (jar) in the listening bundle.

In my case, trying to get the source of the class that the service implements from the reference resulted in null. The reason was that the service was actually created by a class from a third bundle (that class called a method in the registering bundle and used the return value to create the service).

Adding an import for the package in question solved this issue

We are here to answer your question about ServiceTracker sometimes misses services? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji