tags:

views:

60

answers:

1

The OSGi ConfigAdmin passes a Dictionary instance into ManagedService.updated(); the service is then expected to extract the new values from the dictionary. That's great and works fine, but one thing that I have so far not been able to find explained anywhere is whether the dictionary value types are supposed to be specific (Integer, Long, Float, Boolean) or generic Strings that the managed service then parses/converts into a suitable form by itself, instead of expecting the correct value type.

This difference seems innocuous but has pretty grave consequences for subsystem/layer coupling, as the creator of the dictionary and a ManagedService obviously have to agree on the value types.

I have so far not been able to find any recommendation on this; the spec and pretty much all existing examples completely ignore the problem and use either specific types or untyped Strings.

Am I missing something or is this really underspecified?

+4  A: 

There are two answers to this. Firstly, take a look at the MetaType service, which allows your configured bundles to declare all the fields and types that they accept.

But IMHO it is better to make your ManagedService(Factory) implementations robust in the face of a variety of data formats. In particular, ensure that they are always able to handle Strings as a last resort, even if another data type is preferred. This is because some management agents either ignore the MetaType service or they are unable to supply data as any types besides Strings. Felix FileInstall is a good example: it simply reads a Properties file, therefore treating everything as a String.

Be strict in what you send, but generous in what you receive.

Neil Bartlett
The MetaType service was exactly the missing piece of the puzzle. Thanks!
Holger Hoffstätte