Monthly Archives: August 2017

OSGi Declarative Services – Configuration Binding

As explained in OSGi Components – Simply Simple – Part II when using Declarative Services (DS) you get support for configurations stored in a Configuration Admin service for free. When debugging a system, you want to find out if a component is actually using a certain configuration. This post gives you some tips on inspecting your application.

The ServiceComponentRuntime Service

Since R6 of the OSGi specification, the Declarative Service Specification defines the ServiceComponentRuntime service. This service can be used at runtime to get the status of the components and services managed by DS. That service returns the top level DTO named ComponentDescriptionDTO. This is basically a representation of the XML provided by a bundle and read by DS. So the first step is to find the ComponentDescriptionDTO for your component.

Once you have found the description you can use the ServiceComponentRuntime service to get the ComponentConfigurationDTO(s) for the description. This DTO has some useful information about the status of your component. Most importantly it shows whether the component is satisfied. If the component is not satisfied more information about the reason is provided. For example, a reference might not be satisfied. You can now iterate over the references and find the one(s) which is not satisfied.

For configurations, the first check is to see whether the PID of the configuration you are interested in is listed in the configurationPid field of the ComponentDescriptionDTO. However this does not provide you the information whether such a configuration exists and is used by your component.

Therefore you have to check the properties from the ComponentConfigurationDTO and check whether the properties contain a service.pid property and whether the value for this property contains the configuration PID you are interested in. Note that the type of this property can be a String, an array of Strings or a collection of Strings.

This requires a little bit of coding, iterating over the various DTOs and searching for the info you are interested in.

The Declarative Services WebConsole Plugin

Another way of figuring this out without writing code is to use the famous Apache Felix Web Console. The web console allows you to manage and monitor a running OSGi application through a web interface. The Apache Felix project has a plugin for the web console. The Apache Maven coordinates for the current release are org.apache.felix/org.apache.felix.webconsole.plugins.ds/2.0.6.

Once this plugin is installed it gives you an UI for the previously mentioned ServiceComponentRuntime service and you can browse through the DTOs and find the ones you’re interested in.

Bound OSGi Configurations

An OSGi configuration supports the concept of configuration binding. By checking the bundle location field of a configuration object, it is possible to figure our whether a managed service is using this configuration.

However, don’t use this information to figure out whether a configuration is used by a DS component. Configuration binding is considered legacy and more important a DS implementation is not required to bind a configuration to the bundle of a bundle containing the component. While older implementations of the Apache Felix SCR did the configuration binding, newer versions don’t.

Therefore don’t even look there if you want to figure out whether your configuration is used by a DS component.