Getting the service specification and the service filter of an OSGI reference

141 Views Asked by At

Let's say I have an OSGI Bundle that contains the class X. Let's say this class contains an OSGI reference to a specific service. Something like this:

ServiceReference[] references = context.getServiceReferences (serviceSpecification,someFilter);

Is there a way I can dynamically identify the service specification to which the reference is wired? Is there a way to also identify the service filter (second parameter above)?

For example, something like this:

System.out.println(references[0].getServiceSpecification);
System.out.println(references[0].getServiceFilter);

I need to find out these values in a code outside the bundle.

Work done so far:

I used iPOJO to get the reference attribute by creating iPOJO component instance of the bundle, and then getting its property description, as the following:

ComponentInstance  componentInstance = factory.createComponentInstance(configuration);
instanceDescription= (PrimitiveInstanceDescription) componentInstance.getInstanceDescription();
PropertyDescription[] propertyDescription = instanceDescription.getProperties();

I can get the reference name, type, value using the propertyDescription above, but the value is returned as an object, and I am not able to get what I need. Can someone help? Thanks.

1

There are 1 best solutions below

0
On

Please look at Service Hooks. With the Service Hooks, you can hook into service registry operations and observe the finding of services.