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.
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”.
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 - https://www.osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html [2] Eclipse Gemini Blueprint, Compendium Services - https://www.eclipse.org/gemini/blueprint/documentation/reference/1.0.2.RELEASE/html/compendium.html [3] Eclipse Virgo - https://eclipse.org/virgo/ [4] Virgo User Guide, config command - https://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