mmir.ConfigurationManager
A class for managing the configuration.
It's purpose is to load the configuration and settings automatically. This "class" is structured as a singleton - so that only one instance is in use.
It's purpose is to load the configuration and settings automatically. This "class" is structured as a singleton - so that only one instance is in use.
Requires
- module:mmir.require
Members
-
private_confConfigurationManagerModuleConfig
-
-
private_initializedPromise
-
Initialize promise that will be resolve after initialization is completed (set in
init). -
privateconfigDataObject
-
the configuration data (i.e. properties)
-
privateinstanceObject
-
Object containing the instance of the class
mmir.ConfigurationManager. -
privatelistenersmmir.tools.EventEmitter
-
EventEmitter for change-listeners that will be notified on changes on specific configurtion paths (dot-speparated property path)
-
privateloggermmir.tools.Logger
-
Methods
-
private_emitChange(newValue, oldValue, path)
-
HELPER for emitting on-change events to listeners
Name Type Description newValueany the new configuration value oldValueany the old configuration value pathArray.<string> the configuration path, i.e. list of segements of dot-separated path -
private_get(propertyName, defaultValue, setAsDefaultIfUnset){any}
-
Returns the value of a property.
Name Type Description propertyNameString | Array.<String> if String: The name of the property. NOTE: If the property does not exists at the root-level, dot-separated names will be resolved into object-structures, e.g. some.propertywill be resolved so that thevalueat:some: {property: <value>}will be returned if String array: each entry corresponds to component in a dot-separated path (see above)defaultValueany optional OPTIONAL a default value that will be returned, in case there is no property propertyName.setAsDefaultIfUnsetBoolean optional OPTIONAL if true, and there is no value set yet forpropertyName, then the specifieddefaultValuewill be set forpropertyName.
DEFAULT:false
NOTE: if this argument is used, paramdefaultValuemust also be given!Returns:
Type Description any The value of the property -
"Normalizes" a (dot-separated) string or an array into a path: the result is an array of path components (i.e. each path component is a separate entry). NOTE: if propertyName is an Array, its entries are used as-is, i.e. are NOT processed for string-entries that have dot-separating content:
_getAsPath(['dot', 'separated.list']);//-> returns: ['dot', 'separated.list']
Name Type Description propertyNameString | Array.<String> resolves a dot-separated property-name into an array. If propertyNameis an Array, all contained String entries will be resolved, if necessaryReturns:
Type Description Array.<String> list of dot-separated components (without the dots) Example
//result is ['dot', 'separated', 'list'] _getAsPath('dot.separated.list'); _getAsPath(['dot', 'separated', 'list']); -
private_loadConfigFile(callback)
-
Helper that loads configuration file synchronously. Side-Effect: sets
configDatawith loaded configuration data (if successful)Name Type Description callbackfunction optional callback that is invoke after configuration was loaded callback(configData | null)
If loading failed, callback will be invoked withnull. -
private_offChange(propertyName, listener){boolean}
-
Remove listener for configuration changes: if listener was registered multiple times, the first one is removed.
Name Type Description propertyNameString | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be removed from list of listeners for all configuration changes, otherwise it will be removed from listeners for the specified property-path. listenerfunction the listener function that will be invoked when a configuration value is changed: listener(newValue: any, oldValue: any, propertyName: string)
Returns:
Type Description boolean trueif a listener was removed, otherwisefalse. -
private_onChange(propertyName, listener, emitOnAdding)
-
Register listener for configuration changes.
Name Type Description propertyNameString | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be invoked on all configuration changes. If propertyNameis an Array, it will be treated as if its entries were path-elements analogous to a dot-separated String propertyName. NOTE: dot-separated names will be resolved into object-structures, e.g.some.propertywill be resolved so that thevaluewill set to:some: {property: <value>}listenerfunction the listener function that will be invoked when a configuration value is changed: listener(newValue: any, oldValue: any, propertyName: string[])
wherepropertyNameis the list of property-name path components (the last component is the property name itself) NOTE: if parameterpropertyNamewas not specified, the third argument for the listener will be invoked with an empty Array.emitOnAddingBoolean optional OPTIONAL if truethe listener will be immediately be invoked after adding it with the current valuelistener(newValue:
NOTE: can only be used when param, oldValue: undefined, propertyName: ) propertyNameis specified. -
private_set(propertyName, value){any}
-
Sets a property to a given value.
Name Type Description propertyNameString | Array.<String> The name of the property. If propertyNameis an Array, it will be treated as if its entries were path-elements analogous to a dot-separated String propertyName. NOTE: dot-separated names will be resolved into object-structures, e.g.some.propertywill be resolved so that thevaluewill set to:some: {property: <value>}valueany The value of the property Throws:
-
if the propertyName is dot-separated AND one of its path-elements (except for the last) already exists AND its type is not 'object'
- Type
- Error
Returns:
Type Description any The newly set value for the property -
-
addListener(propertyName, listener, emitOnAdding)
-
Register listener for configuration changes.
Name Type Description propertyNameString | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be invoked on all configuration changes. If propertyNameis an Array, it will be treated as if its entries were path-elements analogous to a dot-separated String propertyName. NOTE: dot-separated names will be resolved into object-structures, e.g.some.propertywill be resolved so that thevaluewill set to:some: {property: <value>}listenerfunction the listener function that will be invoked when a configuration value is changed: listener(newValue: any, oldValue: any, propertyName: string[])
wherepropertyNameis the list of property-name path components (the last component is the property name itself) NOTE: if parameterpropertyNamewas not specified, the third argument for the listener will be invoked with an empty Array.emitOnAddingBoolean optional OPTIONAL if truethe listener will be immediately be invoked after adding it with the current valuelistener(newValue:
NOTE: can only be used when param, oldValue: undefined, propertyName: ) propertyNameis specified.- See:
-
privateconstructor()
-
Constructor-Method of Singleton mmir.ConfigurationManager.
-
get(propertyName, defaultValue, setAsDefaultIfUnset){any}
-
Returns the value of a property.
Name Type Description propertyNameString | Array.<String> if String: The name of the property. NOTE: If the property does not exists at the root-level, dot-separated names will be resolved into object-structures, e.g. some.propertywill be resolved so that thevalueat:some: {property: <value>}will be returned if String array: each entry corresponds to component in a dot-separated path (see above)defaultValueany optional OPTIONAL a default value that will be returned, in case there is no property propertyName.setAsDefaultIfUnsetBoolean optional OPTIONAL if true, and there is no value set yet forpropertyName, then the specifieddefaultValuewill be set forpropertyName.
DEFAULT:false
NOTE: if this argument is used, paramdefaultValuemust also be given!- See:
Returns:
Type Description any The value of the property -
getBoolean(defaultValue)
-
Uses
get. If the propertyName does not exists, returnsundefined, otherwise values will be converted into Boolean values. Special case for Strings: the String"false"will be converted to Boolean valuefalse.Name Type Description defaultValueany optional OPTIONAL if a default value is specified and there exists no property propertyName, the specified default value will be returned. NOTE: the default value will also be converted to a Boolean value, if necessary.- See:
-
getNumber(defaultValue)
-
Uses
get. If the property does not exists, returnsundefined, otherwise values will be converted into Number values. If the value has not the type"string", it will be converted byJSON.stringify.Name Type Description defaultValueany optional OPTIONAL if a default value is specified and there exists no property propertyName, the specified default value will be returned. NOTE: the default value will also be converted to a Number value, if necessary.- See:
-
getString(defaultValue)
-
Uses
get. If the property does not exists, returnsundefined, otherwise values will be converted into String values. If the value has not the type"string", it will be converted byJSON.stringify.Name Type Description defaultValueany optional OPTIONAL if a default value is specified and there exists no property propertyName, the specified default value will be returned. NOTE: the default value will also be converted to a String value, if necessary.- See:
-
asyncinit(forceReloadConfig){Promise}
-
Initialize the configuration manager (i.e. loading configuration data etc.)
Name Type Description forceReloadConfigBoolean optional OPTIONAL if FALSY, configuration data will only be loaded, if it has not been loaded yet. If TRUTHY, configuration data will be reloaded regardless, wether it is already available or not. Returns:
Type Description Promise a deferred promise that gets fulfilled when initialization is completed. -
off(propertyName, listener){boolean}
-
Remove listener for configuration changes: if listener was registered multiple times, the first one is removed.
Name Type Description propertyNameString | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be removed from list of listeners for all configuration changes, otherwise it will be removed from listeners for the specified property-path. listenerfunction the listener function that will be invoked when a configuration value is changed: listener(newValue: any, oldValue: any, propertyName: string)
- See:
Returns:
Type Description boolean trueif a listener was removed, otherwisefalse. -
on(propertyName, listener, emitOnAdding)
-
Register listener for configuration changes.
Name Type Description propertyNameString | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be invoked on all configuration changes. If propertyNameis an Array, it will be treated as if its entries were path-elements analogous to a dot-separated String propertyName. NOTE: dot-separated names will be resolved into object-structures, e.g.some.propertywill be resolved so that thevaluewill set to:some: {property: <value>}listenerfunction the listener function that will be invoked when a configuration value is changed: listener(newValue: any, oldValue: any, propertyName: string[])
wherepropertyNameis the list of property-name path components (the last component is the property name itself) NOTE: if parameterpropertyNamewas not specified, the third argument for the listener will be invoked with an empty Array.emitOnAddingBoolean optional OPTIONAL if truethe listener will be immediately be invoked after adding it with the current valuelistener(newValue:
NOTE: can only be used when param, oldValue: undefined, propertyName: ) propertyNameis specified.- See:
-
removeListener(propertyName, listener){boolean}
-
Remove listener for configuration changes: if listener was registered multiple times, the first one is removed.
Name Type Description propertyNameString | Array.<String> optional OPTIONAL The name of the property, to listen for changes: if unspecified, listener will be removed from list of listeners for all configuration changes, otherwise it will be removed from listeners for the specified property-path. listenerfunction the listener function that will be invoked when a configuration value is changed: listener(newValue: any, oldValue: any, propertyName: string)
- See:
Returns:
Type Description boolean trueif a listener was removed, otherwisefalse. -
set(propertyName, value){any}
-
Sets a property to a given value.
Name Type Description propertyNameString | Array.<String> The name of the property. If propertyNameis an Array, it will be treated as if its entries were path-elements analogous to a dot-separated String propertyName. NOTE: dot-separated names will be resolved into object-structures, e.g.some.propertywill be resolved so that thevaluewill set to:some: {property: <value>}valueany The value of the property - See:
Throws:
-
if the propertyName is dot-separated AND one of its path-elements (except for the last) already exists AND its type is not 'object'
- Type
- Error
Returns:
Type Description any The newly set value for the property -
- See: