Search code examples
javaosgideclarative-servicesbnd

Service.FindHook event was'nt called by adding service reference to a component


Today I worked a little bit with OSGi Hooks, specially with FindHook and EventListenerHook for services. I wanted to try out proxying services. The EventListenerHook works fine and my services are proxied. But I realized that the FindHook event would'nt be called if a service will get a reference of the service implementation by annotating the related setXXX method with @Reference (Bnd style). Maybe it is not a problem with the annotation, but with DS in general.

This is quite bad, bc there are two services registered one without proxy and one proxied. I only want to get references from the proxied one. In general, without DS, you can get references by calling BundleContext.getServiceReference(java.lang.Class<S> clazz) and the event FindHook.find will be called, where you can decide which ServiceReference you want to return.

What kind of processes will be executed when I'm using DS like approaches (for me: Bnd annotation @Reference)? As I described in the above section: I want to decide which services should be referenced.


Solution

  • Thanks for the answers, but I found the solution by my own. After hours of debugging I found out that one if condition of my code was violated and nothing specially happened.