Dynamic target queries in OSGi with DS

osgi

Solution

You can always use the target attribute of the reference to peform a first level filter. The if your bind method has the signature

void <method-name>(<parameter-type>, Map);

Then you can run any dynamic filter over the Map which contains the services properties. If the filter does not match, you can ignore that component (for the time being.)

In the alternate, since the component's configuration can contain the reference's target filter, you can modify the component's configuration to alter the target filter.

Problem

When I use a reference in DS I can specify a target that will allow me to narrow down which service instance I want. The problem is that all the examples show static queries that must be done at code time. Is there a way to do a dynamic query (maybe pull in a property from Configuration Admin)? If DS does not support this is there another OSGi dependency injection framework (blueprint, iPojo, etc) that will support this?

Original source