Control Your OSGi Application at Runtime

It is a common procedure to read the initial configuration of a classic Java program from a file system properties file. Once the program is up and running, changes made to the configuration will be ignored unless you deliberately watch for changes to the properties file.
engine order telegraph Control Your OSGi Application at Runtime
OSGi runtimes provide a ConfigurationAdmin[1] to manage your initial configuration and handle changes during runtime. With
Eclipse Gemini Blueprint[2] it is possible to use POJOs like this:

public class EngineOrderTelegraph {
 
  private String order;
 
  public String getOrder() {
    return order;
  }
 
  public void setOrder(String order) {
    System.out.println("Engine order changed to '" + order + "'");
    this.order = order;
  }
}

If you are using Eclipse Virgo[3] you would add your preferences to the pickup directory of your server. To configure the current order of the engine order telegraph to “SLOW (ASTERN)” you’d have to add the following line:

order=SLOW (ASTERN)

The following blueprint configuration assumes that the properties file is named “labX.properties”, and sets the initial order for the engine order telegraph to “STOP”.

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:blueprint-compendium="http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium http://www.eclipse.org/gemini/blueprint/schema/blueprint-compendium/gemini-blueprint-compendium.xsd"
	default-activation="eager">
 
  <bean class="com.eclipsesource.virgo.examples.blueprint.cm.EngineOrderTelegraph">
    <blueprint-compendium:managed-properties persistent-id="labX" autowire-on-update="true" />
    <property name="order" value="STOP" />
  </bean>
</blueprint>

With the OSGi console you can double-check the current configuration with the config command[4].

osgi> config examine labX
 
Factory pid:
Bundle Location: file:/.../virgo-tomcat-server-3.6.2.RELEASE/work/deployer/s/global/47/0/com.eclipsesource.virgo.examples.blueprint.cm.jar/#org.eclipse.virgo.region.user
 
Properties:
    order:
        ASTERN SLOW
    service.pid:
        labX

There is an example of container managed and bean managed use of the ConfigurationAdmin at GitHUB[5].

You have the bridge, Number One

[1] Interface ConfigurationAdmin – http://www.osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html
[2] Eclipse Gemini Blueprint, Compendium Services – http://www.eclipse.org/gemini/blueprint/documentation/reference/1.0.2.RELEASE/html/compendium.html
[3] Eclipse Virgo – http://eclipse.org/virgo/
[4] Virgo User Guide, config command – http://www.eclipse.org/virgo/documentation/virgo-documentation-3.6.2.RELEASE/docs/virgo-user-guide/htmlsingle/virgo-user-guide.html#admin-shell-vsh-config-command
[5] https://github.com/eclipsesource/rap-virgo-examples/tree/master/com.eclipsesource.virgo.examples.blueprint.cm

[image] engine order telegraph – http://www.flickr.com/photos/stevendepolo/

One Response to “Control Your OSGi Application at Runtime”

  1. Just a sidenode: I think handling with the config admin is always a pain especially when I have to write code to do some configuration. Recently I found Apache fileinstall which let you put your configuration in files and watches for changes out of the box.
    http://felix.apache.org/site/apache-felix-file-install.html

One response so far

Written by . Published in Categories: Editors choice, Planet Eclipse, Planet OSGi

Author:
Published:
Aug 5th, 2013