Apache

Apache Felix File Install

File Install is a directory based OSGi management agent. It uses a directory in the file system to install and start a bundle when it is first placed there. It updates the bundle when you update the bundle file in the directory and, when the file is deleted, it will stop and uninstall the bundle.

File Install can do the same for configuration configuration files. This surprisingly simple bundle is very powerful because there are so many programs that work with the file system. For example:

Setup

The bundle runs on any framework. For its configuration, it will use the following system properties:

Property Default Description
felix.fileinstall.poll 2000 ms Number of milliseconds between 2 polls of the directory
felix.fileinstall.dir ./load The name of the directory to watch
felix.fileinstall.debug -1 Debug information
felix.fileinstall.bundles.new.start true Automatically start newly discovered bundles

Once started, the values of these properties are printed to the console.

Configurations

Configuration files are plain property files (java.util.Property). The format is simple:

file ::= ( header | comment ) *
header ::= <header> ( ':' | '=' ) <value> ( '\<nl> <value> ) *
comment ::= '#' <any>

Notice that this model only supports string properties. For example:

# default port
ftp.port = 21

Configuration file names are related to the PID and factory PID. The structure of the file name is as follows:

filename ::= <pid> ( '-' <subname> )? '.cfg'

If the form is <pid>.cfg, the file contains the properties for a Managed Service. The <pid> is then the PID of the Managed Service. See the Configuration Admin service for details.

When a Managed Service Factory is used, the situation is different. The <pid> part then describes the PID of the Managed Service Factory. You can pick any <subname>, this bundle will then create an instance for the factory for each unique name. For example:

com.acme.xyz.cfg // configuration for Managed Service
// com.acme.xyz
com.acme.abc-default.cfg // Managed Service Factory,
// creates an instance for com.acme.abc

Property substitution in configuration files

It is possible to use system properties to specify the values of properties in configuration files. This is achieved through system property substitution, which is instigated by using ${<property>} syntax, where <property> is the name of a system property to substitute.
Example:

ftp.port = ${system.ftp.port}

Watching multiple directories with File Install

Apache Felix File Install provides a ManagedServiceFactory to create multiple instances of File Install. Asuming you have a File Install bundle watching a bundles folder, creating a new instance is as simple as creating a new configuration file org.apache.felix.fileinstall-<pid>.cfg in that folder (substitute <pid> with a unique Id for the new service instance):

org.apache.felix.fileinstall-configDir.cfg
felix.fileinstall.poll=2000
felix.fileinstall.dir=/configDir
felix.fileinstall.debug=-1
felix.fileinstall.bundles.new.start=false