eventstreamr2.configuration¶
- class eventstreamr2.configuration.ConfigurationManager[source]¶
Bases: eventstreamr2.utils.events.Observable
This object manages sotring and accessing configurations.
This object stores individual configurations on a 2-level hierarchy and enables the configurations to be ordered using an arbitary priority system.
The 2 levels are named service_name and source_name to represent the service and the source of the configuration respectively. All configurations under a common service_name are agregated using the ServiceConfigurationWrapper which allows for easy access to individual configuration items.
The priority given to set_config is taken to mean that the larger(numerically) the number, the more important it is. So in the case where 2 configurations provide the same key; the configuration with the larger priority number will be used.
Note
For every successful modification, the observers are notified with 0 or 1 parameters:
- Service Name if there is only a single service affected.
Warning
A notification of modification may not actually affect the data.
Todo
Change the keying order for internal storage to source -> service. And change the priority to be located under the source key(not service).
Variables: configs – A dict storing all the configurations. - get_config(service_name)[source]¶
Gets the service’s configuration wrapped in a ServiceConfigurationWrapper.
Parameters: service_name – The name of the service. Returns: A read only dictionary like object that manages retrieving the configuration in a transparent manner.
- set_config(service_name, source_name, source_priority, new_config=None)[source]¶
Assigns the given configuration to the service’s configuration.
If there is an existing (service_name, source_name) pair then it will be overwritten with the values given. The source name can be reused over multiple service names without any ill effects.
If new_config is missing; it is assumed that no priority is provided.
Parameters: - service_name – The name of the service.
- source_name – The name of the source.
- source_priority (dict or None) – The priority of the source.
- new_config – A mapping containing the configuration.
- delete_service_config(service_name, source_name=None)[source]¶
Removes all configurations under service_name and if specified source_name. If source_name is not specified all configurations a removed.
No operation is performed if service_name is missing, the same applies if the pair service_name and source_name are missing.
Note
This will only fire listeners when it modifies the underlying data. It may not actually change the end-user data.
Parameters: - service_name – The name of the service to remove.
- source_name – The name of source to remove.
- class eventstreamr2.configuration.ServiceConfigurationWrapper(config_manager, service_name)[source]¶
Bases: eventstreamr2.utils.collections.AbstractPriorityDictionary, eventstreamr2.utils.events.Observable
An immutable dictionary which allows easier access to the values stored in ConfigurationManager.
It preferable to use get_config to create an instance of this class.
Warning
A notification of modification may not actually affect the data.
See also
AbstractPriorityDictionary for more information about the avaliable functions.