bmargulies
bmargulies

Reputation: 100013

Configuring an OSGi managed service via the configuration admin API

Consider a managed service registered on SERVICE_PID "a.b.c".

I need to have two different bits of code specify the configuration for a particular factory PID.

ConfigurationAdmin.createFactoryConfiguration() takes just the factory PID, not the instance PID. So, how do I acquire the configuration dictionary for a particular item? For example, felix fileinstall parses a file name like PID-FACTORYPID, and then throws away the FACTORYPID and calls createFactoryConfiguration just on the PID.

If I do likewise, the results flow into the 'updated' method with a PID with a unique string on the end. So I can't come up with the same string later to improve it by calling 'update'.

Upvotes: 1

Views: 291

Answers (2)

Elias Vasylenko
Elias Vasylenko

Reputation: 1534

The answer to this question has changed with OSGi R7. There are two new methods in ConfigurationAdmin that allow you to create a factory configuration with a predictable PID.

  • Configuration getFactoryConfiguration(String factoryPid, String name, String location)

  • Configuration getFactoryConfiguration(String factoryPid, String name)

The resulting PID is constructed by concatenating factoryPid and name with the tilde character ~ as a separator.

Upvotes: 0

Christian Schneider
Christian Schneider

Reputation: 19606

If you create a factory configuration then you can only define the factory pid. The individual config pid is chosen by the config admin impl.

The best way to find such a configuration later is by using a filter for one or some of the properties it has. You can for example give it a property myid=1 and later find it with the filter (myid=1).

Upvotes: 2

Related Questions