public abstract class ConfigurationManager
extends java.lang.Object
Configuration, for instance (properties files, XML
files, properties from a database table, ... ConfigurationPropertyProvider.
Since a configuration manager provides all configurations for components and services, it needs to be initialised before the registry is initialised. How the boot configuration manager is initialised depends on the concrete implementation of the configuration manager. The bootstrapping has to be implemented appropriately. Usually the boot configuration manager is provided its root configuration as file reference or directly as a configuration object. This information needs to be handled by the bootstrapping.
The contents of a configuration depends mainly on the corresponding component/service. This
should declare all needed configuration values as ConfigurationDescription in the
implementing class. Besides this configuration values, there are a few configuration entries
needed for the management of the component, for instance, singleton or multi-instances, and
arbitrary entries for the component itself. These entries can be found in the documentation of a
class requiring the configuration and the
registries.
Components have a type and an instance name which identify them. They are created by adding the
following information to a (parent) configuration: their interface (
Component.<ComponentType> = <InterfaceClass>), an implementation (
<ComponentType>.Implementation = <ImplementationClass> ), instances (
<ComponentType>.Instances = <InstanceName1>, <InstanceName2> ),
and instance implementations supporting the interface of the corresponding component type (
<InstanceName>.Implementation = <ImplementationClass> ).
Each named instance of a component may have its own configuration. This is either a separate
configuration (for instance in a separate file and loaded via the information found in the parent
configuration), or it is contained in the current configuration. However, the latter requires the
configuration entries to have the instance name as prefix. Otherwise there may be naming
conflicts between different component instances having the same name. This in turn requires the
instance names to be unique with respect to a (parent) configuration.
A file name used as configuration for a specific component is searched for in several
configuration directories and therefore needs to be a relative file. They stem from a
ConfigurationPropertyProvider and are usually provided as parameter when bootstrapping.
The configuration directories define an order in which they are searched for the configuration
file. Note that the prefixes for the component (instance) in the separate file need to be
omitted.
All instances of one component type share a common configuration, which is called the type
configuration. This differs from a normal instance just by having the component type instead of
the instance name (as prefix). This component type configuration is also used for the "
anonymous instance", which will be an implicit declared instance if there no component
instances declared explicitly. This anonymous instance is treated as if it had the the component
type name as instance name (that is, it has the component type name twice). Each can have its own
external configuration file which will all be merged:
<ComponentType>.ConfigFile = <RelativePathOfConfigFile> or
<InstanceName>.ConfigFile = <RelativePathOfConfigFile>
Besides the shared configuration each component instance has its own runtime configuration that
is separated from other component instances. It differs from the normal configuration by its
ability to change configuration values at runtime and persist them. This requires a place to
store data, for instance as properties file or in a database. For a component instance there is no difference between a normal and a runtime
configuration; it gets just one merged configuration in which configuration values may be
changed.
Configuration files can also be provided in configuration bundles (in JAR-files). Such a configuration bundle has to have a file "conf/ADEPT2.properties". The file itself may be empty. If one configuration bundle is found, it will be added to the configuration directories. If several configuration bundles are found, they will need to have a defined order via the provided configuration URLs ("arflow.confurl"). Otherwise initialisation will abort.
The configuration directories not only define the order on how to search for externally referenced configuration files and configuration bundles but also the order of the root configuration if provided as file name. Additionally one can set the position (and therefore the priority) of the provided configuration (if provided at all). This splits the configuration directories in 2 parts: the part before the provided configuration and the part after the provided configuration. The runtime configuration always applies at first since these values have the highest priority (especially when changed at runtime).
This configuration manager usually loads all configurations lazily, except the root configuration. All other configurations are loaded as needed and then stored internally for faster subsequent retrieval. If required, for instance when changing the root configuration before bootstrapping or when dumping the root configuration, a complete root configuration will be created. That is all externally referenced configuration files will be incorporated and the reference will be removed from the configuration. Note that this rather complex and should only be done in special cases.
All configuration entries may use variables in their values. They have the form
${arflow:arflow.<VarName>} or ${arflow:confVar.<VarName>}.
The first refers to values set as system properties (see PropertyProvider), which are
usually various directories. The second allows to refer to variables which are declared inside
the root configuration (usually "conf/ADEPT2.properties" and/or the provided
configuration). The declaration is a normal configuration entry:
ConfigurationManager.confVar.<VarName> = <VarValue>. Therefore they may
even use other variables. A cycle in the declaration will abort bootstrapping.
This class parses the following properties from a configuration:
ConfigurationConstants.PROPERTY_CONFIGURATION_FILE)ConfigurationConstants.PROPERTY_CONFIGURATION_FILE)ConfigurationConstants.CONFIG_CONFIGURATION_MANAGER,
ConfigurationConstants.CONFIGURATION_VARIABLE)ConfigurationConstants.PREFIX_PROPERTY_LOGGING)| Modifier and Type | Field and Description |
|---|---|
protected java.util.logging.Logger |
logger
The logger for configuration managers.
|
protected Configuration |
providedConfiguration
The configuration provided when bootstrapping.
|
protected static java.lang.String |
REFERENCED_CONFIG_FILE_SUFFIX
The suffix of configuration entries referring to external configuration files.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ConfigurationManager(Configuration rootConfiguration,
Configuration providedConfiguration,
ConfigurationManager parent)
Creates a new configuration manager having the designated root and provided configuration and
the fields of the designated parent configuration manager.
|
|
ConfigurationManager(java.lang.String rootConfFileName,
Configuration providedConfiguration,
boolean eager,
ConfigurationPropertyProvider provider,
LoggerManager loggerManager)
Creates a new configuration manager using the configuration
properties of the designated provider and either a root configuration
loaded from the designated file name, or the designated provided
configuration or a mixture of both respecting the order of the
configurations and configuration directories from the provider.
|
| Modifier and Type | Method and Description |
|---|---|
Configuration |
cloneConfiguration(Configuration conf)
Clones the designated configuration by iterating all keys and storing the corresponding
property to a new
BaseConfiguration. |
static void |
copyConfiguration(Configuration from,
Configuration to,
java.lang.String prefix)
Gets all entries from the first configuration and stores it with the designated prefix in the
second configuration.
|
abstract ConfigurationManager |
createChild(java.lang.String instanceName,
java.lang.String componentType)
Creates a new configuration manager having all fields set to the same values as this
configuration manager.
|
void |
dumpConfiguration()
Dumps the root configuration to the log of this configuration manager with log level
Level.FINE. |
protected Configuration |
getConfiguration(java.lang.String instanceName)
Gets a configuration for the designated instance name which is a new
Configuration-object. |
Configuration |
getConfiguration(java.lang.String instanceName,
java.lang.String componentType)
Loads the configuration of the designated instance of the designated component type.
|
protected Configuration |
getMergedRootConfiguration()
Gets the root configuration as composite of the currently loaded root configurations from each
configuration directory separately including the provided configuration an the right place.
|
protected java.util.Collection<Pair<java.lang.String,java.lang.String>> |
getReferencedConfigurationFiles(Configuration conf)
Gets all configuration entries that refer to external configuration files in the designated
configuration.
|
Configuration |
getRootConfiguration()
Gets the root configuration of this configuration manager, that is the entry point for
configurations.
|
protected abstract Configuration |
getRuntimeConfiguration(java.lang.String instanceName)
Gets a runtime configuration for the designated instance name which is a
Configuration-object that allows for storing the configuration values, for
instance as file or in a database. |
<C extends Configuration> |
initConfiguration(C conf)
Initialises the designated configuration, for instance, setting the variable replacement.
|
protected Configuration |
initRootConfiguration(java.lang.String rootConfFileName,
boolean eager,
ConfigurationPropertyProvider provider)
Loads the root configuration from the configuration directories, initialises the logging based
on this configuration and the logger manager of this configuration manager and dumps the
configuration if desired.
|
protected Configuration |
loadAndDump(Configuration conf,
boolean eager,
boolean debug)
Loads the designated configuration completely, that is the externally referenced configuration
files will be integrated appropriately in the designated configuration.
|
protected CompositeConfiguration |
loadConfigurationFromFile(java.lang.String instanceName,
java.lang.String fileName,
boolean root)
Loads configuration values out of the configuration directories including the runtime and the
provided configuration in the specified order into a newly created composite configuration.
|
protected Configuration |
loadFromConfDir(java.lang.String instanceName,
java.lang.String fileName,
java.net.URL confDir)
Loads the designated file for the designated instance from the designated configuration
directory.
|
protected void |
loadFromConfDirs(java.lang.String instanceName,
java.lang.String fileName,
CompositeConfiguration conf,
java.util.List<java.net.URL> confDirs,
boolean root)
Loads configuration values out of the designated configuration directories in the specified
order into the designated composite configuration.
|
protected Configuration |
loadReferencedConfigurations(Configuration rootConf)
Eagerly loads all referenced configuration files and puts them in the root configurations per
configuration directory using the appropriate prefix.
|
protected boolean |
loadToRootConfigurations(java.lang.String prefix,
java.lang.String fileName,
java.util.List<java.net.URL> confDirs)
Loads the configuration referred to by the designated file name from the designated
configuration directories and stores them with the designated prefix in the appropriate root
configurations.
|
void |
replaceVariables(java.util.List<java.lang.String> classPath)
Replaces variables with their appropriate values.
|
protected void |
setConfigurationDirectories(ConfigurationPropertyProvider provider)
Sets the configuration directories so that configurations are loaded in the appropriate order,
that is, configuration directories before and after the provided configuration.
|
void |
terminate()
Signals the termination which allows clean-up for instance resetting all created and configured
loggers.
|
protected static final java.lang.String REFERENCED_CONFIG_FILE_SUFFIX
protected final Configuration providedConfiguration
null. If
this is null, only configurations from the configuration directories will be used.protected final java.util.logging.Logger logger
null for usages of the configuration manager without the AristaFlow
platform.public ConfigurationManager(java.lang.String rootConfFileName,
Configuration providedConfiguration,
boolean eager,
ConfigurationPropertyProvider provider,
LoggerManager loggerManager)
throws ConfigurationException
rootConfFileName - The file name (relative to the configuration
directory/directories) of the root configuration for which to
create a UrlConfigurationManager. This may be
null but then a configuration has to be provided (
providedConfiguration).providedConfiguration - The configuration provided when bootstrapping.
This may either be a complete root configuration (without
additional configuration directories), a delta configuration
complementing or overriding the configurations from the
configuration directories or even null. If this is
null, only configurations from the configuration
directories will be used but this requires a valid
rootConfFileName.eager - Whether to (transitively) load all referenced configuration
files for the root configuration when initialising.provider - The provider for configuration properties. Whether they stem from
system properties or some configuration depends on the
implementation of the provider.loggerManager - The logger manager providing and configuring the loggers for the platform.
Logging is initialised right after the root configuration has been initialised. For
the rare usages of a configuration manager without the AristaFlow platform, this may
be null.ConfigurationException - If
ConfigurationException will be thrown.protected ConfigurationManager(Configuration rootConfiguration, Configuration providedConfiguration, ConfigurationManager parent)
rootConfiguration - The root configuration to be used by the newly created configuration
manager. Usually this is a subset of the root configuration of the designated
ConfigurationManager.providedConfiguration - The provided configuration to be used by the newly created
configuration manager. Usually this is a subset of the provided configuration of the
designated ConfigurationManager.parent - The parent ConfigurationManager to retrieve all further fields
from.public Configuration getRootConfiguration()
public void terminate()
protected void setConfigurationDirectories(ConfigurationPropertyProvider provider) throws ConfigurationException
provider - The provider having the configuration directories and the position of the
provided configuration to set. Previous directories take precedence over later
directories.ConfigurationException - If one of the configuration directories cannot be accessed or
the configuration bundle should be used, but there are several configuration bundles
of which the order cannot be determined, a ConfigurationException will
be thrown.protected Configuration initRootConfiguration(java.lang.String rootConfFileName, boolean eager, ConfigurationPropertyProvider provider) throws ConfigurationException
rootConfFileName - The name of the configuration file containing the root configuration.
This name is a relative path with file extension. If this is null, only
the provided configuration will be used.eager - Whether the root configuration should be loaded eagerly, that is all externally
referenced configuration files will be loaded.provider - The provider whether to debug log, that is, load the complete root
configuration and log it.ConfigurationException - If
ConfigurationException will be thrown.protected Configuration loadAndDump(Configuration conf, boolean eager, boolean debug) throws ConfigurationException
Level.FINE.conf - The configuration in which to find externally referenced configuration files and
load them.eager - Whether to lead eagerly, that is whether to load the externally referenced
configuration files independent from whether to log the configuration or not.debug - Whether to log the complete configuration if the log manager is configured
appropriately. If so, this obviously will require all externally referenced
configurations and therefore will load them eagerly.ConfigurationException - If there are problems loading the externally referenced
configuration files, a ConfigurationException will be thrown.protected Configuration loadReferencedConfigurations(Configuration rootConf) throws ConfigurationException
rootConf - The root configuration for which to (transitively) load all referenced
configuration files from the configuration directories.ConfigurationException - If a referenced file name could not be found in any of the
searched configuration directories, a ConfigurationException will be
thrown.protected boolean loadToRootConfigurations(java.lang.String prefix,
java.lang.String fileName,
java.util.List<java.net.URL> confDirs)
prefix - The prefix of the key in the configuration including the component instance name
but without ".ConfigFile".fileName - The name of the configuration file to load with extension (relative path). This
must not be null.confDirs - The configuration directories from which to load the configuration file if
found.protected Configuration getMergedRootConfiguration()
protected java.util.Collection<Pair<java.lang.String,java.lang.String>> getReferencedConfigurationFiles(Configuration conf)
conf - The configuration which to search for externally referenced configuration files.public Configuration getConfiguration(java.lang.String instanceName, java.lang.String componentType) throws ConfigurationException
Configuration
will be created and the contents loaded. The instance configuration will have the corresponding
type configuration as defaults. The configuration will be stored for faster subsequent
requests. If there is no reference to a separate file, the relevant entries from the root
configuration will be returned. instanceName - The name of the instance for which to retrieve the configuration. In case
of the anonymous instance this equals the component type name.componentType - The name of the component type to retrieve the configuration of the
designated instances.ConfigurationException - If the (runtime) configuration for the designated instance can
not be retrieved or it does not contain required entries, a
ConfigurationException will be thrown.ConfigurationException - If
ConfigurationException will be thrown.protected Configuration getConfiguration(java.lang.String instanceName) throws ConfigurationException
Configuration-object. The configuration is loaded from a separate file referenced
in the root configuration via loadConfigurationFromFile(String, String, boolean) or
the relevant entries from the root configuration in case it does not reference a separate file
for the designated name. The prefixes of the entries for the component will be removed in this
case.instanceName - The simple name of the component to get the configuration for.Configuration-object containing either the configurations loaded
from a referenced separate file or having the relevant entries from the root
configuration.ConfigurationException - If
ConfigurationException will be thrown.protected CompositeConfiguration loadConfigurationFromFile(java.lang.String instanceName, java.lang.String fileName, boolean root) throws ConfigurationException
ConfigurationException will be thrown. instanceName - The simple name of the component to get the configuration for or
null for the bootstrapping. null indicates that no runtime
configuration will be used.fileName - The name of the configuration file to load with extension (relative path). If
this is null, only the runtime and the provided configuration will be
used.root - Whether to load a root configuration which does not include the runtime
configuration.ConfigurationException - If
ConfigurationException will be thrown.protected void loadFromConfDirs(java.lang.String instanceName,
java.lang.String fileName,
CompositeConfiguration conf,
java.util.List<java.net.URL> confDirs,
boolean root)
instanceName - The simple name of the component instance to get the configuration for or
null for the bootstrapping. This is only for logging purpose.fileName - The name of the configuration file to load with extension (relative path). This
must not be null.conf - The composite configuration in which to load the found configurations.confDirs - The configuration directories from which to load the configuration file if
found.root - Whether to initialise the root configurations or not.protected Configuration loadFromConfDir(java.lang.String instanceName, java.lang.String fileName, java.net.URL confDir)
instanceName - The simple name of the component instance for which to load a configuration
file. This is only for logging purpose and may be null.fileName - The name of the configuration file to load with extension (relative path) from
the designated configuration directory. This must not be null.confDir - The configuration directory from which to load the configuration from the
designated file.null in case the configuration file cannot be loaded.protected abstract Configuration getRuntimeConfiguration(java.lang.String instanceName) throws ConfigurationException
Configuration-object that allows for storing the configuration values, for
instance as file or in a database. How the configuration is retrieved and where it is stored
depends on the implementing subclass. instanceName - The simple name of the component to get the runtime configuration for.Configuration-object allowing to store configuration values for the
designated instance.ConfigurationException - If the runtime configuration for the designated instance can not
be retrieved or created, a ConfigurationException will be thrown.getConfiguration(String)public void dumpConfiguration()
throws ConfigurationException
Level.FINE. This will load the externally referenced configuration files before. This will also change the root configuration, for instance, in case references to external configuration files have changed.
ConfigurationException - If there are problems loading the externally referenced
configuration files, a ConfigurationException will be thrown.public void replaceVariables(java.util.List<java.lang.String> classPath)
Example: A property, specified in a configuration as:
JDBCDataSource.ConnectionURL = jdbc:derby:${arflow:arflow.datadir}/Derby/DefaultDb;create=true
will have ${arflow:arflow.datadir} replaced with the value of the global data dir,
e.g.:
jdbc:derby:./examples/Derby/DefaultDb;create=true.
classPath - The configuration as a changeable list in which to replace all system
variables.public abstract ConfigurationManager createChild(java.lang.String instanceName, java.lang.String componentType) throws ConfigurationException
null the anonymous instance having the component type name
will be used. If the component type name is also null, the created configuration
manager will have the same root and provided configuration as this configuration manager.instanceName - The simple name of the instance for which to retrieve the configuration. In
case of the anonymous instance this equals the component type name. Use
null for the bootstrap registry.componentType - The name of the component type to retrieve the configuration of the
designated instances. Use null for the bootstrap registry.ConfigurationException - If the configuration for the designated instance cannot be
retrieved, a ConfigurationException will be thrown.public Configuration cloneConfiguration(Configuration conf)
BaseConfiguration. Changes made later to the new configuration
will obviously not be reflected in the old configuration and vice versa. But the lookup map
will be the same, that is, changes to one will also affect the other configuration.conf - The configuration which to clone.public static void copyConfiguration(Configuration from, Configuration to, java.lang.String prefix)
from - The configuration from which to copy all entries from.to - The configuration to copy all the entries to.prefix - The prefix for the entries copied from the first to the second configuration.
This must not be null or the empty string!public <C extends Configuration> C initConfiguration(C conf)
conf - The configuration which to initialise.