FilePersistenceManager
class stores configuration data in properties-like files inside a given directory. All configuration files are located in the same directory. The configuration directory is set by either the {@link #FilePersistenceManager(String)} constructor or the{@link #FilePersistenceManager(BundleContext,String)} constructor. Referto the respective JavaDocs for more information.
When this persistence manager is used by the Configuration Admin Service, the location may be configured using the {@link org.apache.felix.cm.impl.ConfigurationManager#CM_CONFIG_DIR} bundlecontext property. That is the Configuration Admin Service creates an instance of this class calling new FilePersistenceManager(bundleContext, bundleContext.getProperty(CM_CONFIG_DIR))
.
If the location is not set, the config
directory in the current working directory (as set in the user.dir
system property) is used. If the the location is set but, no such directory exists, the directory and any missing parent directories are created. If a file exists at the given location, the constructor fails.
Configuration files are created in the configuration directory by appending the extension .config
to the PID of the configuration. The PID is converted into a relative path name by replacing enclosed dots to slashes. Non-symbolic-name
characters in the PID are encoded with their Unicode character code in hexadecimal.
Examples of PID to name conversion: | |
PID | Configuration File Name |
---|---|
sample | sample.config |
org.apache.felix.log.LogService | org/apache/felix/log/LogService.config |
sample.fläche | sample/fl%00e8che.config |
Mulithreading Issues
In a multithreaded environment the {@link #store(String,Dictionary)} and{@link #load(String)} methods may be called at the the quasi-same time for thesame configuration PID. It may no happen, that the store method starts writing the file and the load method might at the same time read from the file currently being written and thus loading corrupt data (if data is available at all).
To prevent this situation from happening, the methods use synchronization and temporary files as follows:
.tmp
. When done, the file is renamed to actual configuration file name as implied by the PID. This last step of renaming the file is synchronized on the FilePersistenceManager instance.Iterator
returned by {@link #getDictionaries()}is implemented such that any temporary configuration file is just ignored.
|
|
|
|
|
|