简体   繁体   中英

How do i use OSGi managed services and Configuration Admin to store configuration objects?

I am trying to get my head around using the org.osgi.service.cm.ManagedService and Configuration Admin for Apache Felix.

I understand that the ConfigurationAdmin pushes new configurations to the service via the method

public void updated(Dictionary<String, ?> dctnr) throws ConfigurationException

But i have a few questions:

  1. The method signature seems to suggest that i can persist any configuration item in the Configuration, given the Dictionary<String, ?> . Is this the case, or is it only String values that you can use for configuration values? I have yet to find an example that uses anything but Strings.

  2. Given that you can persist Objects as configuration values, what conventions must i follow in order for the Configuration Admin to actually persist them? Must they be Java Beans, or Serializable or JaxB enabled or maybe something else entirely?

  3. Can i somehow get some information out of the Configuration Admin describing the type of the Object that is returned for a particular key? Say that i put a Date in one key, and a String in another, does the application just have to retain this knowledge, or can I get the information from the ManagedService somehow?

The configuration object is defined in the Configuration Admin spec (see OSGi Compendium Release 5 Specification ) as a dictionary of properties. Property values are referred to as the primary property types as defined in the Core spec.

This is the definition of primary property types in OSGi Core Release 5 Specification :

type ::= scalar | collection | array
scalar ::= String | Integer | Long | Float | Double | Byte | Short | Character | Boolean
primitive ::= int | long | float | double | byte | short | char | boolean
array ::= <Array of primitive> | <Array of scalar>
collection ::= <Collection of scalar>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM