开发者

OSGi ConfigAdmin not clear about value types for update Dictionary

开发者 https://www.devze.com 2022-12-18 22:35 出处:网络
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

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号