In the OSGi/iPOJO world, how to get a list of instances of classes implementing an interface?

174 Views Asked by At

In the JavaEE/CDI world, I know how to have the list of instances of classes implementing a given interface : by using Instance<MyInterface> combined with reflections library.

But in the OSGI/iPOJO world, how to do so ?

I know I get one instance by using @Requires MyInterface anInstance. But how can I have a programmatic access to all those classes ?

1

There are 1 best solutions below

2
Clement On BEST ANSWER

Just use the BundleContext:

@Context BundleContext context;

public List<ServiceReference> getInstancesImplementingX() {
    return context.getServiceReferences(X.class);   
}