+

Search Tips   |   Advanced Search

Associate a service with a persisted identity

You associate a set of configuration properties with its consuming component as described in the OSGi Configuration Admin specification using the the persisted identity (PID).

The OSGi Configuration Admin specification provides a number of association mechanisms, of which the following are most commonly used in the Liberty profile:

Register an implementation of org.osgi.service.cm.ManagedService or org.osgi.service.cm.ManagedServiceFactory directly with the OSGi Configuration Admin service (CA)

This is most commonly used in low-level kernel bundles, where service management through OSGi Declarative Services (DS) or Blueprint is not available at bundle start time. The registration specifies the PID that identifies the configuration set to be received.

Define a service to DS

This is the most common way for services in feature bundles to receive their configuration. The service name is used as the PID to associate configuration data. DS receives the configuration set from CA and passes it on to the defined service.


Example

A service might be declared using the following entry in the project *.bnd file:

Service-Component: com.ibm.ws.transaction; \
   provide:='com.ibm.tx.config.ConfigurationProvider'; \
   immediate:='true'; \
   modified:='modified'; \
    implementation:=com.ibm.ws.transaction.services.JTMConfigurationProvider

This generates the following XML code, which can also be coded by the developer instead of using the bnd Service-Component entry:

<component name="com.ibm.ws.transaction" xmlns="http://www.osgi.org/xmlns/scr/v1.1.0"
           immediate="true" modified="modified">
    <implementation class="com.ibm.ws.transaction.services.JTMConfigurationProvider" />
  <service>
      <provide interface="com.ibm.tx.config.ConfigurationProvider" />
  </service>
  <property name="service.vendor" value="IBM" />
</component>

The component name, com.ibm.ws.transaction in this example, is used as the PID for the association of configuration data. If this component does not provide any metadata to describe its configuration, we can specify configuration properties for the component using that PID in server.xml, or an included file, by defining an entry of the following form:


What to do next

Code the service to receive the configuration properties during activation and when the configuration is modified.


Parent topic: Enable a service to receive configuration data

Concepts:

  • Server configuration

    Tasks:

  • Coding the service to receive configuration properties

    Reference:
    OSGi Service Platform Release 4 Version 4.2 Enterprise Specification