Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Configuration

...

Handler

The configuration handler aims to manage component configuration. This handler allows the configuration and dynamic reconfiguration of instances. A configuration is a set of couple (name, value). The name can be a field name or a property name associated to a field or/and a method.

...

To support configuration, the component type needs to declare which properties are configurable. These properties are not necessarily service property but can be internal component property.

Examples

Code Block
xml
xml
<iPOJO>
<Component className="fr.imag.adele.escoffier.hello.impl.HelloServiceImpl">
   <Provides>
       <Property name="foo" field="m_foo"/>
   </Provides>
   <Properties propagation="false"/>
       <Property name="foo" field="m_foo"/>
       <Property name="array" method="updateArray"/>
       <Properties name="hello.language" type="java.lang.String"/>
   </Properties>
</Component>

<instance component="fr.imag.adele.escoffier.hello.impl.HelloServiceImpl" name="HelloService">
   <property name="foo" value="bar"/>
   <property name="array" value="\{1, 2, 3}"/>
   <property name="hello.language" value="en"/>
</instance
</iPOJO>

In the previous snippet, you can see three configurable properties. The first is a configurable property attached to the field 'foo' that is a service property too. The second is an array property attached to a method (updateArrayupdatArray). The third property is a static property, in the sense that neither field nor method is attached to this property.

...

By setting the attribute propagation to "true", you allow the property propagation to the service registration. It means that at each time that the that the configuration of the instance is updated, ; all property properties contained in the configuration is propagate are propagated to the service registrations. For example, in the previous example, not only foo will be published but array and hello.language are also published.
If a property has a method, this method is invoked each time that the property value changes (the method is called to push the initial value just after the constructor). The method receives one argument of the type of the property (an integer array in the example).

Exposing a Managed Service

The ManagedService is a service specified in the OSGi Compendium. It allows reconfiguring an instance with the Configuration Admin. There is two way for an iPOJO instance to expose a Managed Service.
• In the component type description by adding the pid attribute in the properties element
• In the instance configuration by configuring the managed.service.pid property

Code Block
xml
xml

<iPOJO>
<Component className="fr.imag.adele.escoffier.hello.impl.HelloServiceImpl">
   <Provides>
       <Property name="foo" field="m_foo"/>
   </Provides>
   <Properties propagation="false" pid="mymanagedservicepid"/>
       <Property name="foo" field="m_foo"/>
       <Property name="array" method="updateArray"/>
       <Properties name="hello.language" type="java.lang.String"/>
   </Properties>
</Component>

<instance component="fr.imag.adele.escoffier.hello.impl.HelloServiceImpl" name="HelloService">
   <property name="foo" value="bar"/>
   <property name="array" value="\{1, 2, 3}"/>
   <property name="hello.language" value="en"/>
   <property name="managed.service.pid" value="mymanagedservicepid2"/>
</instance
</iPOJO>

Note: if specified in the two locations, the instance configuration is used.

The managed service pid is the identifier used by the Configuration Admin to attach configuration to Managed Services. First this pid must be unique (as any pid in OSGi). Moreover, this pid cannot be the same one that the pid used in the Managed Service Factory to create the instance (if you use this way to create your instance).

When an instance is reconfigured with the Managed Service, the configuration is propagated if the propagation is enabled.

Dynamic Reconfiguration using Factories or ManagedServiceFactories

The handler supports reconfiguration. To reconfigure an instance you can use both iPOJO Factory and the Managed Service Factory ManagedServiceFactory exposed by the factory of the targeted instance. By calling the method reconfigure or update (according of the service do you use), the handler receive the new configuration and apply it. If the propagation is activated, the service registrations are updated too.