| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE- 2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <head> |
| <title>Apache Felix - Combining iPOJO and Configuration Admin</title> |
| <link rel="icon" href="/res/favicon.ico"> |
| |
| <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <meta name="description" content="The most powerful component model for OSGi"> |
| |
| |
| <link href="/ipojo/web/bootstrap/css/bootstrap-cerulean.css" rel="stylesheet"> |
| <link href="/ipojo/web/bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> |
| <link href="/ipojo/web/bootstrap/css/font-awesome.min.css" rel="stylesheet"> |
| <link href="/ipojo/web/style.css" rel="stylesheet"> |
| |
| <!-- Overide alert's colors --> |
| <link href="/ipojo/web/bootstrap/css/alert.css" rel="stylesheet"> |
| |
| <link rel="stylesheet" href="/ipojo/web/github.css" type="text/css" media="all"> |
| |
| |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> |
| <script src="/ipojo/web/bootstrap/js/bootstrap.min.js"></script> |
| |
| </head> |
| |
| <body data-spy="scroll" data-target=".subnav"> |
| <div class="navbar navbar-fixed-top navbar-inverse"> |
| <div class="navbar-inner"> |
| <div class="container"> |
| <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </a> |
| <a class="brand" href="/documentation/subprojects/apache-felix-ipojo.html">Apache Felix iPOJO</a> |
| |
| <div class="nav-collapse" id="main-menu"> |
| <ul class="nav" id="main-menu-left"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/ipojo-news.html">News</a></li> |
| <li><a href="http://felix.apache.org/downloads.cgi">Downloads</a></li> |
| |
| <li class="dropdown"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tutorials <b class="caret"></b></a> |
| <ul class="dropdown-menu" id="tutorials-menu"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-why-choose-ipojo.html">Why choose iPOJO</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-successstories.html">Success stories</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-feature-overview.html">Features</a></li> |
| <li class="divider"></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-in-10-minutes.html">iPOJO in 10 minutes</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/how-to-use-ipojo-annotations.html">Using Annotations</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-hello-word-maven-based-tutorial.html">Maven tutorial</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-advanced-tutorial.html">Advanced tutorial</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/apache-felix-ipojo-dosgi.html">Using Distributed OSGi</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-gettingstarted/ipojo-composition-tutorial.html">Application Composition</a></li> |
| </ul> |
| </li> |
| |
| <li class="dropdown"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#">Documentation <b class="caret"></b></a> |
| <ul class="dropdown-menu" id="user-guide-menu"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html">Requiring a service</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/providing-osgi-services.html">Providing a service</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/lifecycle-callback-handler.html">Lifecycle management</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/configuration-handler.html">Configuration</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/architecture-handler.html">Introspection</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/controller-lifecycle-handler.html">Impacting the lifecycle</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/injecting-bundle-context.html">Accessing the Bundle Context</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/apache-felix-ipojo-instances.html">Creating instances</a></li> |
| <li class="divider"></li> |
| <li class="dropdown-submenu"> |
| <a tabindex="-1" href="#">External <em>handlers</em></a> |
| <ul class="dropdown-menu"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/event-admin-handlers.html">Asynchronous communication</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/ipojo-jmx-handler.html">JMX management</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/extender-pattern-handler.html">Extender pattern</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/white-board-pattern-handler.html">Whiteboard pattern</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/temporal-service-dependency.html">Temporal dependencies</a></li> |
| </ul> |
| </li> |
| <li class="dropdown-submenu"> |
| <a tabindex="-1" href="#">Configuration Admin & Factories</a> |
| <ul class="dropdown-menu"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/combining-ipojo-and-configuration-admin.html">iPOJO and config admin</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/ipojo-factory-service.html">Using the iPOJO Factory service</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/how-to-use-ipojo-factories.html">Factories and Instances</a></li> |
| </ul> |
| </li> |
| <li class="divider"></li> |
| <li class="dropdown-submenu"> |
| <a tabindex="-1" href="#">Advanced topics</a> |
| <ul class="dropdown-menu"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/instance-vs-service-controller.html">Instance vs. Service Controllers</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/service-binding-interceptors.html">Service Binding Interceptors</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/using-xml-schemas.html">XML Schemas</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/apache-felix-ipojo-api.html">Using the iPOJO API</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/constructing-pojo-objects-with-factory-methods.html">Constructing service objects with factory methods</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-ipojo-introspection-api.html">Using the introspection API</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-testing-components.html">Testing components</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/using-stereotypes.html">Using @Stereotypes</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-eclipse-integration.html">Eclipse Integration</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/ipojo-extender-configuration.html">Configuring iPOJO's Extender</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-faq.html">FAQ</a></li> |
| <li class="divider"></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/how-to-write-your-own-handler.html">Handler development</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/how-to-use-ipojo-manipulation-metadata.html">Manipulation Metadata </a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-devguide/dive-into-the-ipojo-manipulation-depths.html">Dive into the iPOJO Manipulation depths</a></li> |
| <li><a href="http://felix.apache.org/ipojo/api/1.12.1">Javadoc</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| |
| <li class="dropdown" id="tools-menu"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#">Tools <b class="caret"></b></a> |
| <ul class="dropdown-menu" id="swatch-menu"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-ant-task.html">Ant Task</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-maven-plug-in.html">Maven Plugin</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-arch-command.html">Architecture commands</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/apache-felix-ipojo-online-manipulator.html">Online Manipulator</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-webconsole-plugin.html">Webconsole plugin</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-tools/ipojo-karaf-feature.html">Apache Karaf Features</a></li> |
| </ul> |
| </li> |
| |
| <li class="dropdown" id="community-menu"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#">Community <b class="caret"></b></a> |
| <ul class="dropdown-menu" id="swatch-menu"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/ipojo-support.html">Support</a></li> |
| <li><a href="http://www.apache.org/">ASF</a></li> |
| <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> |
| <li><a href="http://www.apache.org/foundation/thanks.html">Sponsors</a></li> |
| </ul> |
| </li> |
| |
| <li class="dropdown" id="misc-menu"> |
| <a class="dropdown-toggle" data-toggle="dropdown" href="#">Misc <b class="caret"></b></a> |
| <ul class="dropdown-menu" id="swatch-menu"> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-supportedvms.html">Supported JVMs</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-supportedosgi.html">Supported OSGi Implementations</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/articles-and-presentations.html">Article & Presentations</a></li> |
| <li><a href="/documentation/subprojects/apache-felix-ipojo/developing-camel-mediators-with-ipojo.html">Developping Camel mediators with iPOJO</a></li> |
| </ul> |
| </li> |
| </ul> |
| <ul class="nav pull-right" id="main-menu-right"> |
| <li><a rel="tooltip" target="_blank" href="http://felix.apache.org">Apache Felix <i class="icon-share-alt"></i></a></li> |
| </ul> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <div class="container"> |
| <div class="content"> |
| <style type="text/css"> |
| /* The following code is added by mdx_elementid.py |
| It was originally lifted from http://subversion.apache.org/style/site.css */ |
| /* |
| * Hide class="elementid-permalink", except when an enclosing heading |
| * has the :hover property. |
| */ |
| .headerlink, .elementid-permalink { |
| visibility: hidden; |
| } |
| h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style> |
| <h1 id="combining-ipojo-and-configuration-admin">Combining iPOJO and Configuration Admin<a class="headerlink" href="#combining-ipojo-and-configuration-admin" title="Permanent link">¶</a></h1> |
| <p><em>This page presents how creating, reconfiguring and destroying iPOJO component instance with the OSGi Configuration Admin.</em></p> |
| <div class="toc"> |
| <ul> |
| <li><a href="#combining-ipojo-and-configuration-admin">Combining iPOJO and Configuration Admin</a><ul> |
| <li><a href="#configuration-admin">Configuration Admin</a></li> |
| <li><a href="#why-using-configuration-admin-with-ipojo">Why using Configuration Admin with iPOJO</a></li> |
| <li><a href="#combining-ipojo-and-the-configuration-admin">Combining iPOJO and the Configuration Admin</a></li> |
| <li><a href="#examples">Examples</a><ul> |
| <li><a href="#prerequisites">Prerequisites</a></li> |
| <li><a href="#simple-instantiation">Simple Instantiation</a></li> |
| <li><a href="#reconfiguring-instances-with-the-configuration-admin">Reconfiguring instances with the Configuration Admin</a></li> |
| <li><a href="#property-propagation">Property Propagation</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <h2 id="configuration-admin">Configuration Admin<a class="headerlink" href="#configuration-admin" title="Permanent link">¶</a></h2> |
| <p>The 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.</p> |
| <h2 id="why-using-configuration-admin-with-ipojo">Why using Configuration Admin with iPOJO<a class="headerlink" href="#why-using-configuration-admin-with-ipojo" title="Permanent link">¶</a></h2> |
| <p>As 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: |
| <em> Create new component instances |
| </em> Configuring / reconfiguring these instances |
| <em> Destroying these instances |
| </em> Reconfiguring instances by using Managed Services (not addressed in this page, see <a href="/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/configuration-handler.html">here</a> for further information)</p> |
| <p>The configuration admin is persistent, so stored configuration will be reload it the framework restarts. |
| Moreover, using the configuration admin allows avoiding describing instances inside iPOJO metadata file. These instances are created by inserting new configurations in the configuration admin.</p> |
| <h2 id="combining-ipojo-and-the-configuration-admin">Combining iPOJO and the Configuration Admin<a class="headerlink" href="#combining-ipojo-and-the-configuration-admin" title="Permanent link">¶</a></h2> |
| <p>iPOJO has a component type concept. For each (public) component type, a <code>ManagedServiceFactory</code> 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.</p> |
| <p>If a new Configuration is created:</p> |
| <ul> |
| <li>If the factory is available or an instance is create immediately,</li> |
| <li>Else the factory is not available and the instance will be created as soon as the factory appears.</li> |
| </ul> |
| <h2 id="examples">Examples<a class="headerlink" href="#examples" title="Permanent link">¶</a></h2> |
| <p>This section presents 3 examples about the management of iPOJO instances with the configuration admin:</p> |
| <ul> |
| <li>A simple instantiation example and destruction</li> |
| <li>An instantiation with property injection and dynamic reconfiguration</li> |
| <li>A property propagation example</li> |
| </ul> |
| <p>All these examples are downloadable <a href="http://people.apache.org/~clement/ipojo/tutorials/ca/config.admin.tutorial.zip">here</a>. The archive contains both the project sources and a pre-configured version of felix. |
| To compile the project, launch ant from the <em>config.admin.tutorial</em> directory |
| Then, you can launch Felix by launching the following command from the <code>felix</code> directory:</p> |
| <div class="codehilite"><pre>java -jar bin/felix.jar |
| </pre></div> |
| |
| |
| <h3 id="prerequisites">Prerequisites<a class="headerlink" href="#prerequisites" title="Permanent link">¶</a></h3> |
| <p>Let's take 4 Felix shell commands to manage configuration admin configurations (available in the example archive):</p> |
| <ul> |
| <li><code>create_conf <type> <property-key=property-value></code> allows to create a new Factory Configuration attached to the given type. The configuration contains the given properties.</li> |
| <li><code>update_conf <configuration*name> < property-key=property-value></code> allows to update the configuration with the given name with the given properties.</li> |
| <li><code>delete_conf <configuration*name></code> allows deleting the configuration with the given name. If the name is 'all', delete all stored configurations.</li> |
| <li><code>list_conf</code> allows listing all stored configuration.</li> |
| </ul> |
| <p>Moreover iPOJO and an implementation of the Configuration Admin must be deployed on the gateway:</p> |
| <div class="codehilite"><pre>-> ps |
| START LEVEL 1 |
| ID State Level Name |
| <span class="o">[</span> 0<span class="o">]</span> <span class="o">[</span>Active <span class="o">]</span> <span class="o">[</span> 0<span class="o">]</span> System Bundle <span class="o">(</span>1.0.3<span class="o">)</span> |
| <span class="o">[</span> 1<span class="o">]</span> <span class="o">[</span>Active <span class="o">]</span> <span class="o">[</span> 1<span class="o">]</span> Apache Felix Shell Service <span class="o">(</span>1.0.0<span class="o">)</span> |
| <span class="o">[</span> 2<span class="o">]</span> <span class="o">[</span>Active <span class="o">]</span> <span class="o">[</span> 1<span class="o">]</span> Apache Felix Shell TUI <span class="o">(</span>1.0.0<span class="o">)</span> |
| <span class="o">[</span> 3<span class="o">]</span> <span class="o">[</span>Active <span class="o">]</span> <span class="o">[</span> 1<span class="o">]</span> Apache Felix Bundle Repository <span class="o">(</span>1.0.2<span class="o">)</span> |
| <span class="o">[</span> 4<span class="o">]</span> <span class="o">[</span>Active <span class="o">]</span> <span class="o">[</span> 1<span class="o">]</span> Apache Felix Configuration Admin Service <span class="o">(</span>1.0.10<span class="o">)</span> |
| <span class="o">[</span> 5<span class="o">]</span> <span class="o">[</span>Active <span class="o">]</span> <span class="o">[</span> 1<span class="o">]</span> Apache Felix iPOJO <span class="o">(</span>1.2.0<span class="o">)</span> |
| <span class="o">[</span> 6<span class="o">]</span> <span class="o">[</span>Active <span class="o">]</span> <span class="o">[</span> 1<span class="o">]</span> Apache Felix iPOJO Arch Command <span class="o">(</span>1.2.0<span class="o">)</span> |
| </pre></div> |
| |
| |
| <h3 id="simple-instantiation">Simple Instantiation<a class="headerlink" href="#simple-instantiation" title="Permanent link">¶</a></h3> |
| <p>Imagine the following very simple component implementation:</p> |
| <div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Hello1</span> <span class="o">{</span> |
| <span class="kd">public</span> <span class="nf">Hello1</span><span class="o">()</span> <span class="o">{</span> |
| <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"Hello"</span><span class="o">);</span> |
| <span class="o">}</span> |
| <span class="o">}</span> |
| </pre></div> |
| |
| |
| <p>The component type is defined with following metadata:</p> |
| <div class="codehilite"><pre><span class="nt"><component</span> |
| <span class="na">classname=</span><span class="s">"org.apache.felix.ipojo.example.ca.component.Hello1"</span> |
| <span class="na">factory=</span><span class="s">"hello1"</span> <span class="na">immediate=</span><span class="s">"true"</span> <span class="na">architecture=</span><span class="s">"true"</span><span class="nt">/></span> |
| </pre></div> |
| |
| |
| <p>The defined component type (<em>Hello1</em>) just creates a Hello1 object when the instance is created (thanks to the <em>immediate</em> attribute). |
| So if we deploy this bundle and add a consistent configuration we obtain (note that bundle need to be already compiled):</p> |
| <div class="codehilite"><pre>-> start file:..<span class="se">\c</span>onfig.admin.tutorial<span class="se">\o</span>utput<span class="se">\c</span>onfig.admin.tutorial.jar |
| -> create_conf org.apache.felix.ipojo.example.ca.component.Hello1 |
| Insert the configuration : <span class="o">{</span>org.apache.felix.ipojo.example.ca.component.Hello1<span class="o">}</span> |
| -> Hello |
| </pre></div> |
| |
| |
| <p><em>Note</em>: Debug messages from the configuration admin were removed |
| So as predicted, the Hello message appears. To be really sure of the creating, we can ask for the instance architecture (the component type allows architecture introspection thank to the architecture attribute):</p> |
| <div class="codehilite"><pre>-> arch |
| Instance ArchCommand -> valid |
| Instance org.apache.felix.ipojo.example.ca.component.Hello1.e40fe80a-2c0d-4c51-b00b-a82565874cd8 -> valid |
| -> |
| -> arch -instance |
| org.apache.felix.ipojo.example.ca.component.Hello1.e40fe80a-2c0d-4c51-b00b-a82565874cd8 |
| instance <span class="nv">name</span><span class="o">=</span> |
| <span class="s2">"org.apache.felix.ipojo.example.ca.component.Hello1.e40fe80a-2c0d-4c51-b00b-a82565874cd8"</span> |
| component.type<span class="o">=</span><span class="s2">"hello1"</span> |
| <span class="nv">state</span><span class="o">=</span><span class="s2">"valid"</span> <span class="nv">bundle</span><span class="o">=</span><span class="s2">"7"</span> |
| object <span class="nv">name</span><span class="o">=</span><span class="s2">"org.apache.felix.ipojo.example.ca.component.Hello1@120cc56"</span> |
| handler |
| <span class="nv">name</span><span class="o">=</span><span class="s2">"org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler"</span> |
| <span class="nv">state</span><span class="o">=</span><span class="s2">"valid"</span> |
| handler |
| <span class="nv">name</span><span class="o">=</span><span class="s2">"org.apache.felix.ipojo.handlers.architecture.ArchitectureHandler"</span> |
| <span class="nv">state</span><span class="o">=</span><span class="s2">"valid"</span> |
| -> |
| </pre></div> |
| |
| |
| <p>So, the instance is correctly created. The name of the instance was created by the configuration admin. It could change according to your configuration admin implementation. |
| Then, we can delete the instance by removing the configuration from the configuration admin:</p> |
| <div class="codehilite"><pre>-> delete_conf |
| org.apache.felix.ipojo.example.ca.component.Hello1.e40fe80a-2c0d-4c51-b00b-a82565874cd8 |
| Delete the configuration : |
| org.apache.felix.ipojo.example.ca.component.Hello1.e40fe80a-2c0d-4c51-b00b-a82565874cd8 |
| -> arch |
| Instance ArchCommand -> valid |
| </pre></div> |
| |
| |
| <p>So, arch does no more displayed any <em>hello</em> instances, the created instance was disposed.</p> |
| <h3 id="reconfiguring-instances-with-the-configuration-admin">Reconfiguring instances with the Configuration Admin<a class="headerlink" href="#reconfiguring-instances-with-the-configuration-admin" title="Permanent link">¶</a></h3> |
| <p>Imagine the following component implementation:</p> |
| <div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">Hello2</span> <span class="o">{</span> |
| <span class="n">String</span> <span class="n">m_name</span><span class="o">;</span> |
| <span class="kd">public</span> <span class="kt">void</span> <span class="nf">stop</span><span class="o">()</span> <span class="o">{</span> |
| <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"Good by "</span> <span class="o">+</span> <span class="n">m_name</span><span class="o">);</span> |
| <span class="o">}</span> |
| <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setName</span><span class="o">(</span><span class="n">String</span> <span class="n">newName</span><span class="o">)</span> <span class="o">{</span> |
| <span class="n">m_name</span> <span class="o">=</span> <span class="n">newName</span><span class="o">;</span> |
| <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">"Hello "</span> <span class="o">+</span> <span class="n">m_name</span><span class="o">);</span> |
| <span class="o">}</span> |
| <span class="o">}</span> |
| </pre></div> |
| |
| |
| <p>And the following metadata:</p> |
| <div class="codehilite"><pre><span class="nt"><component</span> |
| <span class="na">classname=</span><span class="s">"org.apache.felix.ipojo.example.ca.component.Hello2"</span> |
| <span class="na">factory=</span><span class="s">"hello2"</span> <span class="na">immediate=</span><span class="s">"true"</span> <span class="na">architecture=</span><span class="s">"true"</span><span class="nt">></span> |
| <span class="nt"><callback</span> <span class="na">transition=</span><span class="s">"validate"</span> <span class="na">method=</span><span class="s">"stop"</span><span class="nt">/></span> |
| <span class="nt"><properties></span> |
| <span class="nt"><property</span> <span class="na">field=</span><span class="s">"m_name"</span> <span class="na">name=</span><span class="s">"to"</span> <span class="na">method=</span><span class="s">"setName"</span><span class="nt">/></span> |
| <span class="nt"></properties></span> |
| <span class="nt"></component></span> |
| </pre></div> |
| |
| |
| <p>The defined component type (<em>Hello2</em>) write "Hello + $name" when the property 'to' (attached to the field m_name) receive a new value. A value is necessary insert in the instance configuration. Moreover when killed, the instance will display a "Good By" message. |
| Let's play a simple scenario:</p> |
| <ul> |
| <li>Create a Hello2 instance</li> |
| <li>Update the instance configuration</li> |
| <li>Kill the created instance</li> |
| </ul> |
| <p> </p> |
| <div class="codehilite"><pre>-> create_conf org.apache.felix.ipojo.example.ca.component.Hello2 <span class="nv">to</span><span class="o">=</span>ipojo |
| Insert the configuration : |
| <span class="o">{</span>service.factoryPid<span class="o">=</span>org.apache.felix.ipojo.example.ca.component.Hello2, <span class="nv">to</span><span class="o">=</span>ipojo<span class="o">}</span> |
| Created configuration: |
| org.apache.felix.ipojo.example.ca.component.Hello2.75082279-9b4b-4c49-b0e0-8efb38b67aa3 |
| Hello ipojo |
| -> list_conf |
| org.apache.felix.ipojo.example.ca.component.Hello2.75082279-9b4b-4c49-b0e0-8efb38b67aa3 : |
| <span class="o">{</span>service.pid<span class="o">=</span>org.apache.felix.ipojo.example.ca.component.Hello2.75082279-9b4b-4c49-b0e0-8efb38b67aa3, |
| service.factorypid<span class="o">=</span>org.apache.felix.ipojo.example.ca.component.Hello2, |
| <span class="nv">to</span><span class="o">=</span>ipojo<span class="o">}</span> |
| -> update_conf |
| org.apache.felix.ipojo.example.ca.component.Hello2.75082279-9b4b-4c49-b0e0-8efb38b67aa3 <span class="nv">to</span><span class="o">=</span>felix |
| Update: |
| <span class="nv">pid</span><span class="o">=</span>org.apache.felix.ipojo.example.ca.component.Hello2.75082279-9b4b-4c49-b0e0-8efb38b67aa3 |
| Update the configuration : <span class="o">{</span><span class="nv">to</span><span class="o">=</span>felix<span class="o">}</span> |
| Hello felix |
| -> delete_conf |
| org.apache.felix.ipojo.example.ca.component.Hello2.75082279-9b4b-4c49-b0e0-8efb38b67aa3 |
| Delete the configuration : |
| org.apache.felix.ipojo.example.ca.component.Hello2.75082279-9b4b-4c49-b0e0-8efb38b67aa3 |
| Good by felix-> list_conf |
| </pre></div> |
| |
| |
| <p>In this simple scenario, we see that when the configuration is updated, the instance receives the new value. The <em>setName</em> 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. Obviously it is possible to create several instance of the same type:</p> |
| <div class="codehilite"><pre>-> create_conf org.apache.felix.ipojo.example.ca.component.Hello2 <span class="nv">to</span><span class="o">=</span>ipojo |
| Insert the configuration : |
| <span class="o">{</span>service.factoryPid<span class="o">=</span>org.apache.felix.ipojo.example.ca.component.Hello2, <span class="nv">to</span><span class="o">=</span>ipojo<span class="o">}</span> |
| Hello ipojo |
| -> create_conf org.apache.felix.ipojo.example.ca.component.Hello2 <span class="nv">to</span><span class="o">=</span>felix |
| Insert the configuration : |
| <span class="o">{</span>service.factoryPid<span class="o">=</span>org.apache.felix.ipojo.example.ca.component.Hello2, <span class="nv">to</span><span class="o">=</span>felix<span class="o">}</span> |
| Hello felix |
| -> arch |
| Instance ArchCommand -> valid |
| Instance org.apache.felix.ipojo.example.ca.component.Hello2.aaf1927c-1a81-490d-bd7b-21b13d454987 -> valid |
| Instance org.apache.felix.ipojo.example.ca.component.Hello2.9344fdbe-c35e-4afc-b839-f7ad0ea59a9d -> valid |
| </pre></div> |
| |
| |
| <p>The 'arch' command displays the two created instances.</p> |
| <div class="alert alert-info info" markdown="1"> |
| <h4>Delete configurations</h4> |
| <p>you can delete all created configurations with the delete_conf all command</p> |
| </div> |
| |
| <h3 id="property-propagation">Property Propagation<a class="headerlink" href="#property-propagation" title="Permanent link">¶</a></h3> |
| <p>It is possible to propagate the instance configuration to the published service properties. To activate property propagation you need to write the <em>'propagation'</em> attribute in the 'properties' element as in</p> |
| <div class="codehilite"><pre><span class="nt"><component</span> |
| <span class="na">classname=</span><span class="s">"org.apache.felix.ipojo.example.ca.component.Hello3"</span> |
| <span class="na">factory=</span><span class="s">"hello3"</span> <span class="na">architecture=</span><span class="s">"true"</span><span class="nt">></span> |
| <span class="nt"><provides/></span> |
| <span class="nt"><properties</span> <span class="na">propagation=</span><span class="s">"true"</span><span class="nt">></span> |
| <span class="nt"><property</span> <span class="na">field=</span><span class="s">"m_name"</span> <span class="na">value=</span><span class="s">"clement"</span><span class="nt">/></span> |
| <span class="nt"></properties></span> |
| <span class="nt"></component></span> |
| </pre></div> |
| |
| |
| <p>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. So create an instance of the Hello3 component type as follow:</p> |
| <div class="codehilite"><pre>-> create_conf org.apache.felix.ipojo.example.ca.component.Hello3 |
| Insert the configuration : |
| <span class="o">{</span>service.factoryPid<span class="o">=</span>org.apache.felix.ipojo.example.ca.component.Hello3<span class="o">}</span> |
| </pre></div> |
| |
| |
| <p>Then, you can check provided services with the <em>services 7</em> command</p> |
| <div class="codehilite"><pre>-> services 7 |
| // Factories and Managed Service factories // |
| ---- |
| factory.name <span class="o">=</span> org.apache.felix.ipojo.example.ca.component.Hello3 |
| instance.name <span class="o">=</span> |
| org.apache.felix.ipojo.example.ca.component.Hello3.a5ca5901-6e20-4636-8805-fbca2db1d68b |
| <span class="nv">objectClass</span> <span class="o">=</span> org.apache.felix.ipojo.example.ca.service.Hello |
| service.factoryPid <span class="o">=</span> org.apache.felix.ipojo.example.ca.component.Hello3 |
| service.id <span class="o">=</span> 69 |
| -> |
| </pre></div> |
| |
| |
| <p>Now, we update the instance configuration with a new property 'p1':</p> |
| <div class="codehilite"><pre>-> update_conf |
| org.apache.felix.ipojo.example.ca.component.Hello3.a5ca5901-6e20-4636-8805-fbca2db1d68b <span class="nv">p1</span><span class="o">=</span>v1 |
| Update the configuration : <span class="o">{</span><span class="nv">p1</span><span class="o">=</span>v1<span class="o">}</span> |
| -> services 7 |
| config.admin.tutorial <span class="o">(</span>7<span class="o">)</span> provides: |
| // Factories and Managed Service factories // |
| ---- |
| factory.name <span class="o">=</span> org.apache.felix.ipojo.example.ca.component.Hello3 |
| instance.name <span class="o">=</span> |
| org.apache.felix.ipojo.example.ca.component.Hello3.a5ca5901-6e20-4636-8805-fbca2db1d68b |
| <span class="nv">objectClass</span> <span class="o">=</span> org.apache.felix.ipojo.example.ca.service.Hello |
| <span class="nv">p1</span> <span class="o">=</span> v1 |
| service.factoryPid <span class="o">=</span> org.apache.felix.ipojo.example.ca.component.Hello3 |
| service.id <span class="o">=</span> 69 |
| </pre></div> |
| |
| |
| <p>Remark that the new property p1 is published. |
| Now we can remove this property by reconfiguring the instance with an empty configuration:</p> |
| <div class="codehilite"><pre>-> update_conf |
| org.apache.felix.ipojo.example.ca.component.Hello3.a5ca5901-6e20-4636-8805-fbca2db1d68b |
| Update the configuration : <span class="o">{}</span> |
| -> services 7 |
| ConfigAdminExample <span class="o">(</span>8<span class="o">)</span> provides: |
| // Factories and Managed Service factories // |
| ---- |
| factory.name <span class="o">=</span> org.apache.felix.ipojo.example.ca.component.Hello3 |
| instance.name <span class="o">=</span> |
| org.apache.felix.ipojo.example.ca.component.Hello3.a5ca5901-6e20-4636-8805-fbca2db1d68b |
| <span class="nv">objectClass</span> <span class="o">=</span> org.apache.felix.ipojo.example.ca.service.Hello |
| service.factoryPid <span class="o">=</span> org.apache.felix.ipojo.example.ca.component.Hello3 |
| service.id <span class="o">=</span> 69 |
| </pre></div> |
| |
| |
| <p>The service does no more publish the <code>p1</code> property.</p> |
| </div> |
| </div> |
| |
| <hr/> |
| |
| <div class="container"> |
| <footer id="footer"> |
| <div class="row"> |
| <div class="trademarkFooter span7"> |
| Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project |
| logo are trademarks of The Apache Software Foundation. All other marks mentioned |
| may be trademarks or registered trademarks of their respective owners. |
| </div> |
| <div class="timestamp span3 offset2"> |
| Rev. 1700393 by cziegeler on Tue, 1 Sep 2015 06:04:06 +0000 |
| </div> |
| </div> |
| </footer> |
| </div> |
| </body> |
| |
| <script type="text/javascript"> |
| var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
| </script> |
| |
| <script type="text/javascript"> |
| try{ |
| var pageTracker = _gat._getTracker("UA-1518442-4"); |
| pageTracker._trackPageview(); |
| } catch(err) {} |
| </script> |
| |
| </html> |