Clement Escoffier | 6b928e9 | 2008-05-16 20:33:54 +0000 | [diff] [blame^] | 1 | |
| 2 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <HTML> |
| 4 | |
| 5 | |
| 6 | <HEAD> |
| 7 | <TITLE>Apache Felix - Configuration Handler</TITLE> |
| 8 | <LINK rel="stylesheet" href="http://felix.apache.org/site/media.data/site.css" type="text/css" media="all"> |
| 9 | <META http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
| 10 | </HEAD> |
| 11 | <BODY> |
| 12 | <DIV class="title"><DIV class="logo"><A href="http://felix.apache.org/site/index.html"><IMG border="0" alt="Apache Felix" src="http://felix.apache.org/site/media.data/logo.png"></A></DIV><DIV class="header"><A href="http://www.apache.org/"><IMG border="0" alt="Apache" src="http://felix.apache.org/site/media.data/apache.png"></A></DIV></DIV> |
| 13 | <DIV class="menu"> |
| 14 | <UL> |
| 15 | <LI><A href="http://felix.apache.org/site/news.html" title="news">news</A></LI> |
| 16 | <LI><A href="http://felix.apache.org/site/license.html" title="license">license</A></LI> |
| 17 | <LI><SPAN class="nobr"><A href="http://felix.apache.org/site/downloads.cgi" title="Visit page outside Confluence" rel="nofollow">downloads<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></LI> |
| 18 | <LI><A href="http://felix.apache.org/site/documentation.html" title="documentation">documentation</A></LI> |
| 19 | <LI><A href="http://felix.apache.org/site/mailinglists.html" title="mailinglists">mailing lists</A></LI> |
| 20 | <LI><A href="http://felix.apache.org/site/contributing.html" title="Contributing">contributing</A></LI> |
| 21 | <LI><SPAN class="nobr"><A href="http://www.apache.org/" title="Visit page outside Confluence" rel="nofollow">asf<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></LI> |
| 22 | <LI><SPAN class="nobr"><A href="http://www.apache.org/foundation/sponsorship.html" title="Visit page outside Confluence" rel="nofollow">sponsorship<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></LI> |
| 23 | <LI><SPAN class="nobr"><A href="http://www.apache.org/foundation/thanks.html" title="Visit page outside Confluence" rel="nofollow">sponsors<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN> |
| 24 | <!-- ApacheCon Ad --> |
| 25 | <IFRAME src="http://www.apache.org/ads/button.html" style="border-width:0; float: left" frameborder="0" scrolling="no" width="135" height="135"></IFRAME> |
| 26 | <P style="height: 100px"> |
| 27 | <!-- ApacheCon Ad --></LI> |
| 28 | </UL> |
| 29 | </DIV> |
| 30 | <DIV class="main"> |
| 31 | <TABLE class="sectionMacro" border="0" cellpadding="5" cellspacing="0" width="100%"><TBODY><TR> |
| 32 | <TD class="confluenceTd" valign="top" width="80%"> |
| 33 | <H1><A name="ConfigurationHandler-ConfigurationHandler"></A>Configuration Handler</H1> |
| 34 | |
| 35 | <P>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.</P> |
| 36 | |
| 37 | <H2><A name="ConfigurationHandler-ConfigurablePropertyconfiguration"></A>Configurable Property configuration</H2> |
| 38 | |
| 39 | <P>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.</P> |
| 40 | |
| 41 | |
| 42 | <H2><A name="ConfigurationHandler-Examples"></A>Examples</H2> |
| 43 | |
| 44 | <DIV class="code"><DIV class="codeContent"> |
| 45 | <PRE class="code-xml"><SPAN class="code-tag"><iPOJO></SPAN> |
| 46 | <SPAN class="code-tag"><Component className=<SPAN class="code-quote">"fr.imag.adele.escoffier.hello.impl.HelloServiceImpl"</SPAN>></SPAN> |
| 47 | <SPAN class="code-tag"><Provides></SPAN> |
| 48 | <SPAN class="code-tag"><Property name=<SPAN class="code-quote">"foo"</SPAN> field=<SPAN class="code-quote">"m_foo"</SPAN>/></SPAN> |
| 49 | <SPAN class="code-tag"></Provides></SPAN> |
| 50 | <SPAN class="code-tag"><Properties propagation=<SPAN class="code-quote">"false"</SPAN>/></SPAN> |
| 51 | <SPAN class="code-tag"><Property name=<SPAN class="code-quote">"foo"</SPAN> field=<SPAN class="code-quote">"m_foo"</SPAN>/></SPAN> |
| 52 | <SPAN class="code-tag"><Property name=<SPAN class="code-quote">"array"</SPAN> method=<SPAN class="code-quote">"updateArray"</SPAN>/></SPAN> |
| 53 | <SPAN class="code-tag"><Properties name=<SPAN class="code-quote">"hello.language"</SPAN> type=<SPAN class="code-quote">"java.lang.String"</SPAN>/></SPAN> |
| 54 | <SPAN class="code-tag"></Properties></SPAN> |
| 55 | <SPAN class="code-tag"></Component></SPAN> |
| 56 | |
| 57 | <SPAN class="code-tag"><instance component=<SPAN class="code-quote">"fr.imag.adele.escoffier.hello.impl.HelloServiceImpl"</SPAN> name=<SPAN class="code-quote">"HelloService"</SPAN>></SPAN> |
| 58 | <SPAN class="code-tag"><property name=<SPAN class="code-quote">"foo"</SPAN> value=<SPAN class="code-quote">"bar"</SPAN>/></SPAN> |
| 59 | <SPAN class="code-tag"><property name=<SPAN class="code-quote">"array"</SPAN> value=<SPAN class="code-quote">"\{1, 2, 3}"</SPAN>/></SPAN> |
| 60 | <SPAN class="code-tag"><property name=<SPAN class="code-quote">"hello.language"</SPAN> value=<SPAN class="code-quote">"en"</SPAN>/></SPAN> |
| 61 | </instance |
| 62 | <SPAN class="code-tag"></iPOJO></SPAN></PRE> |
| 63 | </DIV></DIV> |
| 64 | <P>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 (updatArray). The third property is a <EM>static</EM> property, in the sense that neither field nor method is attached to this property.</P> |
| 65 | |
| 66 | <P>These three properties are configured by the instance configuration.</P> |
| 67 | |
| 68 | <P>By setting the attribute <B>propagation</B> to <B>"true"</B>, you allow the property propagation to the service registration. It means that at each time that the configuration of the instance is updated; all properties contained in the configuration are propagated to the service registrations. For example, in the previous example, not only <EM>foo</EM> will be published but <EM>array</EM> and <EM>hello.language</EM> are also published.<BR> |
| 69 | 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).</P> |
| 70 | |
| 71 | <H2><A name="ConfigurationHandler-ExposingaManagedService"></A>Exposing a Managed Service</H2> |
| 72 | <P>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.<BR> |
| 73 | • In the component type description by adding the <EM>pid</EM> attribute in the properties element <BR> |
| 74 | • In the instance configuration by configuring the <EM>managed.service.pid</EM> property</P> |
| 75 | <DIV class="code"><DIV class="codeContent"> |
| 76 | <PRE class="code-xml"><SPAN class="code-tag"><iPOJO></SPAN> |
| 77 | <SPAN class="code-tag"><Component className=<SPAN class="code-quote">"fr.imag.adele.escoffier.hello.impl.HelloServiceImpl"</SPAN>></SPAN> |
| 78 | <SPAN class="code-tag"><Provides></SPAN> |
| 79 | <SPAN class="code-tag"><Property name=<SPAN class="code-quote">"foo"</SPAN> field=<SPAN class="code-quote">"m_foo"</SPAN>/></SPAN> |
| 80 | <SPAN class="code-tag"></Provides></SPAN> |
| 81 | <SPAN class="code-tag"><Properties propagation=<SPAN class="code-quote">"false"</SPAN> pid=<SPAN class="code-quote">"mymanagedservicepid"</SPAN>/></SPAN> |
| 82 | <SPAN class="code-tag"><Property name=<SPAN class="code-quote">"foo"</SPAN> field=<SPAN class="code-quote">"m_foo"</SPAN>/></SPAN> |
| 83 | <SPAN class="code-tag"><Property name=<SPAN class="code-quote">"array"</SPAN> method=<SPAN class="code-quote">"updateArray"</SPAN>/></SPAN> |
| 84 | <SPAN class="code-tag"><Properties name=<SPAN class="code-quote">"hello.language"</SPAN> type=<SPAN class="code-quote">"java.lang.String"</SPAN>/></SPAN> |
| 85 | <SPAN class="code-tag"></Properties></SPAN> |
| 86 | <SPAN class="code-tag"></Component></SPAN> |
| 87 | |
| 88 | <SPAN class="code-tag"><instance component=<SPAN class="code-quote">"fr.imag.adele.escoffier.hello.impl.HelloServiceImpl"</SPAN> name=<SPAN class="code-quote">"HelloService"</SPAN>></SPAN> |
| 89 | <SPAN class="code-tag"><property name=<SPAN class="code-quote">"foo"</SPAN> value=<SPAN class="code-quote">"bar"</SPAN>/></SPAN> |
| 90 | <SPAN class="code-tag"><property name=<SPAN class="code-quote">"array"</SPAN> value=<SPAN class="code-quote">"\{1, 2, 3}"</SPAN>/></SPAN> |
| 91 | <SPAN class="code-tag"><property name=<SPAN class="code-quote">"hello.language"</SPAN> value=<SPAN class="code-quote">"en"</SPAN>/></SPAN> |
| 92 | <SPAN class="code-tag"><property name=<SPAN class="code-quote">"managed.service.pid"</SPAN> value=<SPAN class="code-quote">"mymanagedservicepid2"</SPAN>/></SPAN> |
| 93 | </instance |
| 94 | <SPAN class="code-tag"></iPOJO></SPAN></PRE> |
| 95 | </DIV></DIV> |
| 96 | <P><EM>Note</EM>: if specified in the two locations, the instance configuration is used.</P> |
| 97 | |
| 98 | <P>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).</P> |
| 99 | |
| 100 | <P>When an instance is reconfigured with the Managed Service, the configuration is propagated if the propagation is enabled.</P> |
| 101 | |
| 102 | <H2><A name="ConfigurationHandler-DynamicReconfigurationusingFactoriesorManagedServiceFactories"></A>Dynamic Reconfiguration using Factories or ManagedServiceFactories</H2> |
| 103 | <P>The handler supports reconfiguration. To reconfigure an instance you can use both iPOJO Factory and the ManagedServiceFactory exposed by the factory of the targeted instance. By calling the method <EM>reconfigure</EM> or <EM>update</EM> (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.</P></TD> |
| 104 | <TD class="confluenceTd" valign="top" width="20%"> |
| 105 | <FORM method="get" class="confluence-searchbox marginlessForm " action="http://felix.apache.org/confluence/dosearchsite.action"> |
| 106 | <INPUT type="hidden" name="searchQuery.spaceKey" value="FELIX"> |
| 107 | <INPUT type="text" name="searchQuery.queryString"> |
| 108 | <INPUT type="submit" value="Search"> |
| 109 | </FORM> |
| 110 | <HR> |
| 111 | <H6><A name="ConfigurationHandler-Overview"></A><B>Overview</B></H6> |
| 112 | <UL> |
| 113 | <LI><A href="http://felix.apache.org/site/apache-felix-ipojo-2.html" title="Apache Felix iPOJO-2">Home Page</A></LI> |
| 114 | <LI><A href="http://felix.apache.org/site/apache-felix-ipojo-feature-overview.html" title="Apache Felix iPOJO Feature Overview">iPOJO Feature Overview</A></LI> |
| 115 | <LI><A href="http://felix.apache.org/site/download.html" title="Download">Download & Install </A></LI> |
| 116 | </UL> |
| 117 | |
| 118 | |
| 119 | <H6><A name="ConfigurationHandler-GettingStarted"></A><B>Getting Started</B></H6> |
| 120 | <UL> |
| 121 | <LI><A href="http://felix.apache.org/site/ipojo-in-10-minutes.html" title="iPOJO in 10 minutes">iPOJO in 10 minutes</A></LI> |
| 122 | <LI><A href="http://felix.apache.org/site/ipojo-hello-word-maven-based-tutorial.html" title="iPOJO Hello Word (Maven-Based) tutorial">iPOJO Hello Word (Maven-Based) tutorial</A></LI> |
| 123 | <LI><A href="http://felix.apache.org/site/ipojo-advanced-tutorial.html" title="iPOJO Advanced Tutorial">iPOJO Advanced Tutorial</A></LI> |
| 124 | </UL> |
| 125 | |
| 126 | |
| 127 | <H6><A name="ConfigurationHandler-UserGuide"></A><B>User Guide</B></H6> |
| 128 | <UL> |
| 129 | <LI><A href="http://felix.apache.org/site/describing-components.html" title="Describing components">Describing components</A></LI> |
| 130 | <LI><A href="http://felix.apache.org/site/how-to-use-ipojo-annotations.html" title="How to use iPOJO Annotations">How to use iPOJO Annotations</A></LI> |
| 131 | <LI><A href="http://felix.apache.org/site/ipojo-advanced-topics.html" title="iPOJO Advanced Topics">Advanced Topics</A></LI> |
| 132 | <LI><A href="http://felix.apache.org/site/ipojo-faq.html" title="iPOJO FAQ">FAQ</A></LI> |
| 133 | </UL> |
| 134 | |
| 135 | |
| 136 | <H6><A name="ConfigurationHandler-Tools"></A><B>Tools</B></H6> |
| 137 | <UL> |
| 138 | <LI><A href="http://felix.apache.org/site/ipojo-eclipse-plug-in.html" title="iPOJO Eclipse Plug-in">iPOJO Eclipse Plug-in</A></LI> |
| 139 | <LI><A href="http://felix.apache.org/site/ipojo-ant-task.html" title="iPOJO Ant Task">iPOJO Ant Task</A></LI> |
| 140 | <LI><A href="http://felix.apache.org/site/ipojo-maven-plug-in.html" title="iPOJO Maven Plug-in">iPOJO Maven Plug-in</A></LI> |
| 141 | <LI><A href="http://felix.apache.org/site/ipojo-concepts-overview.html" title="iPOJO Concepts Overview">iPOJO concepts overview</A></LI> |
| 142 | </UL> |
| 143 | |
| 144 | |
| 145 | <H6><A name="ConfigurationHandler-DeveloperGuide"></A><B>Developer Guide</B></H6> |
| 146 | <UL> |
| 147 | <LI><A href="http://felix.apache.org/site/how-to-write-your-own-handler.html" title="How to write your own handler">How to write your own handler</A></LI> |
| 148 | <LI><A href="http://felix.apache.org/site/how-to-use-ipojo-manipulation-metadata.html" title="How to use iPOJO Manipulation Metadata">How to use iPOJO Manipulation Metadata</A></LI> |
| 149 | </UL> |
| 150 | |
| 151 | |
| 152 | <H6><A name="ConfigurationHandler-Misc%26Contact"></A><B>Misc & Contact</B></H6> |
| 153 | <UL> |
| 154 | <LI><A href="http://felix.apache.org/site/apache-felix-ipojo-issuestracker.html" title="apache-felix-ipojo-issuestracker">Issues Tracker</A></LI> |
| 155 | <LI><SPAN class="nobr"><A href="http://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=FELIX&title=Supported%20JVMs&linkCreation=true&fromPageId=82824" title="Create Page: Supported JVMs" class="createlink">Supported JVMs<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/plus.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></LI> |
| 156 | <LI><SPAN class="nobr"><A href="http://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=FELIX&title=Supported%20OSGi%20Implementations&linkCreation=true&fromPageId=82824" title="Create Page: Supported OSGi Implementations" class="createlink">Supported OSGi Implementations<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/plus.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></LI> |
| 157 | <LI><A href="http://felix.apache.org/site/future-ideas.html" title="Future Ideas">Future Ideas</A></LI> |
| 158 | <LI><SPAN class="nobr"><A href="http://cwiki.apache.org/confluence/pages/createpage.action?spaceKey=FELIX&title=Contact&linkCreation=true&fromPageId=82824" title="Create Page: Contact" class="createlink">Contact<SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/plus.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></LI> |
| 159 | <LI><A href="http://felix.apache.org/site/related-works.html" title="Related Works">Related Works</A></LI> |
| 160 | <LI><A href="http://felix.apache.org/site/article-presentations.html" title="Article & Presentations">Article & Presentations</A></LI> |
| 161 | </UL> |
| 162 | |
| 163 | |
| 164 | <HR> |
| 165 | <DIV class="" align="center"> |
| 166 | <P><SPAN class="nobr"><A href="http://cwiki.apache.org/confluence/createrssfeed.action?types=blogpost&statuses=created&statuses=modified&spaces=FELIX&labelString=iPOJO&rssType=atom&maxResults=10&timeSpan=5&publicFeed=true&title=iPOJO%20Atom%20Feed" title="Stay tuned!" rel="nofollow"><IMG src="http://cwiki.apache.org/confluence/images/icons/feed-icon-32x32.png" align="absmiddle" border="0"><SUP><IMG class="rendericon" src="http://cwiki.apache.org/confluence/images/icons/linkext7.gif" height="7" width="7" align="absmiddle" alt="" border="0"></SUP></A></SPAN></P></DIV></TD></TR></TBODY></TABLE> |
| 167 | </DIV> |
| 168 | </BODY> |
| 169 | |
| 170 | |
| 171 | </HTML> |