-
Notifications
You must be signed in to change notification settings - Fork 2
Dynamic configurations
Dave Reynolds edited this page Jan 19, 2014
·
1 revision
Appbase provides support for monitoring a directory (tree) of configuration files and updating configurations when files are added, removed or changed. This is generally used during development to enable easy update to configured items such as apis or templates, and then disabled at production time.
The primary class which enables this is ConfigMonitor
. This creates and maintains a list of configured instance objects matching the entries in the monitored directory. It is an abstract class and you subclass it to define the function which creates the instance objects from the discovered configuration files.
The configuration options for a ConfigMonitor are:
Parameter | Meaning |
---|---|
directory |
the directory to be monitored |
scanInterval |
adjust the frequency of scanning for changes, default is 2 seconds, time in ms |
productionMode |
set to true to disable timed scanning, only an initial scan will be done at app startup and any manual explicit scans |
fileSampleLength |
set a length for a prefix of the scanned files which will be included in the change checking, the default is 0 which means that only the file length and lastModified times are used, checking file content is only necessary if you need subsecond resolution of changes, e.g. when writing tests |
waitForStable |
by default if the scan finds a file has changed then the configuration will be updated, this may (rarely) result in trying to configure from a partially written file, this can be prevented by setting waitForStable to true in which case the scanner has to see the file checksum stable for two consecutive scans before it will trigger a reconfiguration |
The primary methods are:
Method | Meansing |
---|---|
getEntries() |
return a collection of all the configured objects |
getLatest(entry) |
return the latest version of the given entry |
refresh() |
force an immediate scan for changed configurations, useful if the monitor is in production mode |