|
Page Created :
FELIX :
Combining iPOJO and Configuration Admin
Combining iPOJO and Configuration Admin has been created by Clement Escoffier (May 24, 2007). Content:This page presents how creating, reconfiguring and destroying iPOJO component instance with the OSGi Configuration Admin. Configuration AdminThe Configuration Admin service is a configuration manager describe in the OSGi R4 Compendium. It allows an operator to set the configuration information of deployed applications. The Configuration Admin defines the Configuration as the process of defining the configuration data of applications and assuring that those applications receive that data when they are running. The Configuration Admin is becoming an important piece on OSGi Gateway. It is become the standard way to configure applications on OSGi gateways. Why using Configuration Admin with iPOJOAs the configuration admin offer an administration support, it seems reasonable to combine iPOJO and the Configuration Admin to control the gateway. Indeed, thanks to the configuration admin it should be possible to:
The configuration admin is persistent, so stored configuration will be reload it the framework restarts. Combining iPOJO and the Configuration AdminiPOJO has a component type concept. For each (public) component type, a ManagedServiceFactory is published. For each configurations matching with the component type from the Configuration Admin, a new component instance is created. Moreover, when this configuration is updated, the instance is dynamically reconfigured. If the configuration is removed, the instance is disposed. If a new Configuration is created:
ExamplesThis section presents 3 examples about the management of iPOJO instances with the configuration admin:
All these examples are downloadable here PrerequisitesLet's take 4 Felix shell commands to manage configuration admin configurations:
Moreover iPOJO and an implementation of the Configuration Admin must be deployed on the gateway: -> ps
START LEVEL 1
ID State Level Name
[ 0] [Active ] [ 0] System Bundle (0.9.0.incubator-SNAPSHOT)
[ 1] [Active ] [ 1] Apache Felix Shell Service (0.9.0.incubator_SNAPSHOT)
[ 2] [Active ] [ 1] Apache Felix Shell TUI (0.9.0.incubator_SNAPSHOT)
[ 3] [Active ] [ 1] Apache Felix Bundle Repository (0.9.0.incubator_SNAPSHOT)
[ 4] [Active ] [ 1] Apache Felix Configuration Admin Service (0.9.0.incubator_SNAPSHOT)
[ 5] [Active ] [ 1] iPOJO (0.7.1.incubator_SNAPSHOT)
[ 6] [Active ] [ 1] OSGi R4 Compendium Bundle (4)
[ 7] [Active ] [ 1] javax.servlet-2.3 (0)
-> create_conf hello2 to=clement
Insert the configuration : {service.factoryPid=hello2, to=clement}
Hello clement
-> list_conf
hello2.e41713c3-9ff8-4bbb-a128-97d267962e58 : {service.pid=hello2.e41713c3-9ff8-4bbb-a128-97d267962e58, service.factorypid=hello2, to=clement}
-> update_conf hello2.e41713c3-9ff8-4bbb-a128-97d267962e58 to=Rick
Update the configuration : {service.pid=hello2.e41713c3-9ff8-4bbb-a128-97d267962e58, service.factorypid=hello2, to=Rick}
Hello Rick
-> delete_conf hello2.e41713c3-9ff8-4bbb-a128-97d267962e58
Delete the configuration : hello2.e41713c3-9ff8-4bbb-a128-97d267962e58
Good by Rick
In this simple scenario, we see that when updated the attached configuration, the instance receives the new value. The setName method is immediately invoked to inject the new value. Moreover, when the configuration is deleted, the instance is going to be killed: the "Good Bye" message appears and the instance is disposed. -> create_conf hello2 to=clement
Insert the configuration : {service.factoryPid=hello2, to=clement}
Hello clement
-> create_conf hello2 to=rick
Insert the configuration : {service.factoryPid=hello2, to=rick}
Hello rick
-> arch
Instance hello2.3d64ae54-98ae-43f4-845a-15956b2a78ce -> valid
Instance hello2.b5e3fc82-25bf-4191-bb56-f5afe516e2fa -> valid
The 'arch' command displays the two created instances. Property PropagationIt is possible to propagate the instance configuration to the published service properties. To activate property propagation you need to write the 'configurable' attribute in the 'properties' element as in <component classname="org.apache.felix.ipojo.example.ca.component.Hello3" factory="hello3" architecture="true"> <provides/> <properties configurable="true"> <property field="m_name" value="clement"/> </properties> </component> The defined type provides a service. Moreover it supports properties propagation. So all property, except listed one (m_name), will be published inside the provided services. factory.pid = hello3 objectClass = org.apache.felix.ipojo.example.ca.service.Hello service.factoryPid = hello3 service.id = 287 service.pid = hello3.e964c4e0-029f-4e49-a7cd-a4d8880f20c1 Now, we update the instance configuration with a new property 'p1': -> update_conf hello3.e964c4e0-029f-4e49-a7cd-a4d8880f20c1 p1=v1
Update the configuration : {p1=v1}
-> Remove : {service.pid=hello3.e964c4e0-029f-4e49-a7cd-a4d8880f20c1, service.factoryPid=hello3}
-> services 8
ConfigAdminExample (8) provides:
----
factory.pid = hello3
objectClass = org.apache.felix.ipojo.example.ca.service.Hello
p1 = v1
service.factoryPid = hello3
service.id = 287
service.pid = hello3.e964c4e0-029f-4e49-a7cd-a4d8880f20c1
Remark that the new property p1 is published. -> update_conf hello3.e964c4e0-029f-4e49-a7cd-a4d8880f20c1
Update the configuration : {}
-> services 8
ConfigAdminExample (8) provides:
----
factory.pid = hello3
objectClass = org.apache.felix.ipojo.example.ca.service.Hello
service.factoryPid = hello3
service.id = 287
service.pid = hello3.e964c4e0-029f-4e49-a7cd-a4d8880f20c1
The service does no more publish the p1 property. ConclusionThis page has presented how to combine the configuration admin and iPOJO. If you have any comment or question, do not hesitate to send me an email |
Unsubscribe or edit your notifications preferences
