Class UrlConfigurationManager
- java.lang.Object
-
- de.aristaflow.adept2.base.configuration.ConfigurationManager
-
- de.aristaflow.adept2.base.registry.UrlConfigurationManager
-
public class UrlConfigurationManager extends ConfigurationManager
This configuration manager extends a normal configuration manager by the means for runtime configurations. This can either be based on files or stemming from a JDBC data source. Therefore this configuration manager needs access to a registry to retrieve the data source. A configuration manager is initialised before a registry, therefore early services like registries or theJDBCDataSource
s cannot use a runtime configuration from a data source but only from files.Runtime configuration files have a default configuration directory that can be set via a (system) property. If none is specified, a subdirectory of the data directory will be used. The runtime configuration of a specific component instance will be a file in this directory having the simple instance component name as name. However, this file can be explicitly configured:
<InstanceName>.RuntimeConfiguration.File = <RelativePathOfRTConfigFile>
or<InstanceName>.RuntimeConfiguration.File = <AbsolutePathOfRTConfigFile>
.
The path may be relative to the runtime configuration directory or it may be absolute. It can either be a file or aURL
but it must be writable.A runtime configuration from a database table needs a
JDBCDataSource
which needs to be configured:
<InstanceName>.RuntimeConfiguration.JDBCDataSource = <SimpleNameOfJDBCDataSource>
.This class parses the following properties from a configuration:
- <ComponentType>.RuntimeConfiguration.File (
ConfigurationConstants.PROPERTY_CONFIGURATION_RUNTIME_PREFIX
,ConfigurationConstants.PROPERTY_CONFIGURATION_RUNTIME_FILE
) - <InstanceName>.RuntimeConfiguration.File (
ConfigurationConstants.PROPERTY_CONFIGURATION_RUNTIME_PREFIX
,ConfigurationConstants.PROPERTY_CONFIGURATION_RUNTIME_FILE
) - <ComponentType>.RuntimeConfiguration.JDBCDataSource (
ConfigurationConstants.PROPERTY_CONFIGURATION_RUNTIME_PREFIX
,ConfigurationConstants.PROPERTY_CONFIGURATION_RUNTIME_DATA_SOURCE
) - <InstanceName>.RuntimeConfiguration.JDBCDataSource (
ConfigurationConstants.PROPERTY_CONFIGURATION_RUNTIME_PREFIX
,ConfigurationConstants.PROPERTY_CONFIGURATION_RUNTIME_DATA_SOURCE
) - ConfigurationManager.confVars.<VarName> (
ConfigurationConstants.CONFIG_CONFIGURATION_MANAGER
,ConfigurationConstants.CONFIGURATION_VARIABLE
)
- <ComponentType>.RuntimeConfiguration.File (
-
-
Field Summary
Fields Modifier and Type Field Description protected NameResolution
nameResolution
The resolution for service names.protected String
rtConfDataSource
The simple name of the default JDBC data source used for configurations that can be changed at runtime.protected File
runtimeConfigDir
The directory to store configurations that can be changed at runtime.-
Fields inherited from class de.aristaflow.adept2.base.configuration.ConfigurationManager
logger, providedConfiguration, REFERENCED_CONFIG_FILE_SUFFIX
-
-
Constructor Summary
Constructors Modifier Constructor Description UrlConfigurationManager(String rootConfFileName, org.apache.commons.configuration2.Configuration providedConfiguration, boolean eager, ConfigurationPropertyProvider provider, LoggerManager loggerManager)
Creates a newUrlConfigurationManager
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.protected
UrlConfigurationManager(org.apache.commons.configuration2.Configuration rootConfiguration, org.apache.commons.configuration2.Configuration providedConfiguration, UrlConfigurationManager parent)
Creates a newUrlConfigurationManager
having the designated root and provided configuration and the fields of the designatedUrlConfigurationManager
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UrlConfigurationManager
createChild(String instanceName, String componentType)
Creates a new configuration manager having all fields set to the same values as this configuration manager.protected org.apache.commons.configuration2.Configuration
getRtConfigDsFor(String instanceName, String simpleDsName)
Gets the runtime configuration based on a data base table from the designated data source.protected org.apache.commons.configuration2.Configuration
getRuntimeConfigDataSource(String instanceName)
Gets the runtime configuration based on a data base table from a data source that is specified for the designated instance in the root configuration.protected String
getRuntimeConfigDataSourceConfigKey(String instanceName)
Returns the configuration key to be looked up in the root configuration for retrieving the data source instance name to be used for the runtime configuration of the service specified with the given simple instance name.protected String
getRuntimeConfigDataSourceName(String instanceName)
Returns the simple instance name of the JDBCDataSource to be used for the runtime configuration of the given service instance (simple) or null if none.protected org.apache.commons.configuration2.Configuration
getRuntimeConfigFile(String instanceName)
Gets the runtime configuration based on a file (or URL) specified for the designated instance in the root configuration.protected org.apache.commons.configuration2.Configuration
getRuntimeConfiguration(String instanceName)
Gets a runtime configuration for the designated instance name which is aConfiguration
-object that allows for storing the configuration values, for instance as file or in a database.protected org.apache.commons.configuration2.Configuration
initRootConfiguration(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.static org.apache.commons.configuration2.DatabaseConfiguration
newDatabaseConfiguration(Logger logger, JDBCDataSource dataSource, String tableName, String keyColumn, String valueColumn)
Creates a newDatabaseConfiguration
using the designated table and columns to store the configuration in the designated data source.protected void
setRegistry(LocalServiceRegistry registry, SessionFactory sessionFactory, URI[] uris)
Sets the registry, the session factory and the URIs to be used for retrievingJDBCDataSource
s for runtime configurations.-
Methods inherited from class de.aristaflow.adept2.base.configuration.ConfigurationManager
cloneConfiguration, copyConfiguration, dumpConfiguration, getConfiguration, getConfiguration, getMergedRootConfiguration, getReferencedConfigurationFiles, getRootConfiguration, initConfiguration, loadAndDump, loadConfigurationFromFile, loadFromConfDir, loadFromConfDirs, loadReferencedConfigurations, loadToRootConfigurations, replaceVariables, setConfigurationDirectories, terminate
-
-
-
-
Field Detail
-
nameResolution
protected final NameResolution nameResolution
The resolution for service names.
-
rtConfDataSource
protected String rtConfDataSource
The simple name of the default JDBC data source used for configurations that can be changed at runtime. This will only be used if no explicit data source and no explicit file is configured for a component (instance). This may benull
meaning that theglobal directory
should be used.
-
runtimeConfigDir
protected final File runtimeConfigDir
The directory to store configurations that can be changed at runtime. This will only be used if no explicit data source and no explicit file is configured for a component (instance) as well as noglobal data source
.
-
-
Constructor Detail
-
UrlConfigurationManager
public UrlConfigurationManager(String rootConfFileName, org.apache.commons.configuration2.Configuration providedConfiguration, boolean eager, ConfigurationPropertyProvider provider, LoggerManager loggerManager) throws ConfigurationException
Creates a newUrlConfigurationManager
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.- Parameters:
rootConfFileName
- The file name (relative to the configuration directory/directories) of the root configuration for which to create aUrlConfigurationManager
. This may benull
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 evennull
. If this isnull
, only configurations from the configuration directories will be used but this requires a validrootConfFileName
.eager
- Whether to (transitively) load all referenced configuration files for the root configuration when initialising.provider
- The provider for configuration properties.loggerManager
- The logger manager providing and configuring the loggers for the platform. Logging is initialised right after the root configuration has been initialised.- Throws:
ConfigurationException
- If- there is no root configuration file name and no valid provided configuration,
- there is no valid provided configuration and no configuration directory has been set,
- one of the configuration directories cannot be accessed,
- the configuration bundle order is not defined,
- the designated root configuration file name could not be found in any of the searched configuration directories,
- the directory for storing the logs can not be created or it is a file or
- there are problems eagerly loading the externally referenced configuration files,
ConfigurationException
will be thrown.
-
UrlConfigurationManager
protected UrlConfigurationManager(org.apache.commons.configuration2.Configuration rootConfiguration, org.apache.commons.configuration2.Configuration providedConfiguration, UrlConfigurationManager parent)
Creates a newUrlConfigurationManager
having the designated root and provided configuration and the fields of the designatedUrlConfigurationManager
.- Parameters:
rootConfiguration
- The root configuration to be used by the newly created configuration manager. Usually this is a subset of the root configuration of the designatedUrlConfigurationManager
.providedConfiguration
- The provided configuration to be used by the newly created configuration manager. Usually this is a subset of the provided configuration of the designatedUrlConfigurationManager
.parent
- The parentUrlConfigurationManager
to retrieve all further fields from.
-
-
Method Detail
-
setRegistry
protected void setRegistry(LocalServiceRegistry registry, SessionFactory sessionFactory, URI[] uris)
Sets the registry, the session factory and the URIs to be used for retrievingJDBCDataSource
s for runtime configurations. Before this method is called no runtime configurations from databases are available. Early loaded components can only use files for runtime configurations.
This is also used to change the session factory after the global security manager has become available.- Parameters:
registry
- The registry to retrieve theJDBCDataSource
s from.sessionFactory
- The session factory to retrieve theJDBCDataSource
s with.uris
- The URIs for the session tokens to retrieve theJDBCDataSource
s with.
-
initRootConfiguration
protected org.apache.commons.configuration2.Configuration initRootConfiguration(String rootConfFileName, boolean eager, ConfigurationPropertyProvider provider) throws ConfigurationException
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.If the default data source should be used for runtime configurations, this data source will be loaded.
- Overrides:
initRootConfiguration
in classConfigurationManager
- Parameters:
rootConfFileName
- The name of the configuration file containing the root configuration. This name is a relative path with file extension. If this isnull
, 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.- Returns:
- The root configuration loaded from the configuration directories and having the provided configuration integrated.
- Throws:
ConfigurationException
- If- the designated (non-null) file name could not be found in any of the searched configuration directories,
- the directory for storing the logs can not be created or it is a file or
- there are problems loading the externally referenced configuration files,
ConfigurationException
will be thrown.
-
getRuntimeConfiguration
protected org.apache.commons.configuration2.Configuration getRuntimeConfiguration(String instanceName) throws ConfigurationException
Gets a runtime configuration for the designated instance name which is aConfiguration
-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.
The returned configuration must not have unnecessary prefixes for its entries, for instance there must not be the instance name as prefix. This would render the returned configuration unusable by the component instance since this does not know its instance name and therefore does not find the expected configuration entries.Tries to load the runtime configuration from the configured data source, the configured file name (or URL) or from the global runtime configuration directory. The first found runtime configuration will be used. If no runtime configuration is found,
null
will be returned.- Specified by:
getRuntimeConfiguration
in classConfigurationManager
- Parameters:
instanceName
- The simple name of the component to get the runtime configuration for.- Returns:
- A new
Configuration
-object allowing to store configuration values for the designated instance. - Throws:
ConfigurationException
- If a runtime configuration file is not a valid file or it can not be written, aConfigurationException
will be thrown.ConfigurationException
- If- there are problems retrieving the configured file or URL,
- the file or URL does not allow write access, or
- there are problems loading the properties from the file or URL,
- there are problems retrieving the data source for the runtime configuration table,
ConfigurationException
will be thrown.- See Also:
ConfigurationManager.getConfiguration(String)
-
getRuntimeConfigFile
protected org.apache.commons.configuration2.Configuration getRuntimeConfigFile(String instanceName) throws ConfigurationException
Gets the runtime configuration based on a file (or URL) specified for the designated instance in the root configuration. This may either be absolute or relative (to the global runtime configuration directory. If this is not set,null
will be returned.- Parameters:
instanceName
- The simple name of the component to get the runtime configuration for.- Returns:
- The runtime configuration specified as file or URL in the root configuration for the designated instance.
- Throws:
ConfigurationException
- If- the configured URL is absolute but cannot be resolved,
- the configured URL is relative and cannot be resolved to the global runtime configuration directory,
- the file or URL does not allow write access, or
- there are problems loading the properties,
ConfigurationException
will be thrown.
-
getRuntimeConfigDataSource
protected org.apache.commons.configuration2.Configuration getRuntimeConfigDataSource(String instanceName) throws ConfigurationException
Gets the runtime configuration based on a data base table from a data source that is specified for the designated instance in the root configuration. If no data source is set,null
will be returned.- Parameters:
instanceName
- The simple name of the component to get the runtime configuration for.- Returns:
- The runtime configuration based on a data base table from a configured data source.
- Throws:
ConfigurationException
- If- the registry is not set for retrieving the data source,
- the configured data source cannot be retrieved or
- checking for the existence of the data base table fails,
ConfigurationException
will be thrown.
-
getRuntimeConfigDataSourceConfigKey
protected String getRuntimeConfigDataSourceConfigKey(String instanceName)
Returns the configuration key to be looked up in the root configuration for retrieving the data source instance name to be used for the runtime configuration of the service specified with the given simple instance name.- Parameters:
instanceName
- The simple instance name of the service for which the configuration key should be created.- Returns:
- The configuration key for looking up the simple instance name of the runtime configuration data source.
-
getRuntimeConfigDataSourceName
protected String getRuntimeConfigDataSourceName(String instanceName)
Returns the simple instance name of the JDBCDataSource to be used for the runtime configuration of the given service instance (simple) or null if none.- Parameters:
instanceName
- The simple instance name of the service to find the runtime configuration data source instance name for.- Returns:
- The simple instance name of the JDBCDataSource to be used for the given service instance name or null of none.
-
getRtConfigDsFor
protected org.apache.commons.configuration2.Configuration getRtConfigDsFor(String instanceName, String simpleDsName) throws ConfigurationException
Gets the runtime configuration based on a data base table from the designated data source.- Parameters:
instanceName
- The simple name of the component to get the runtime configuration for.simpleDsName
- The simple name of the data source from which to retrieve the runtime configuration.- Returns:
- The runtime configuration based on a data base table from the designated data source.
- Throws:
ConfigurationException
- If- the registry is not set for retrieving the designated data source,
- the designated data source cannot be retrieved,
- the database configuration cannot be created or
- checking for the existence of the data base table fails,
ConfigurationException
will be thrown.
-
createChild
public UrlConfigurationManager createChild(String instanceName, String componentType) throws ConfigurationException
Description copied from class:ConfigurationManager
Creates a new configuration manager having all fields set to the same values as this configuration manager. The root configuration will be the configuration of the designated instance, the provided configuration will be the appropriate subset of the provided configuration of this configuration manager.
If the instance name isnull
the anonymous instance having the component type name will be used. If the component type name is alsonull
, the created configuration manager will have the same root and provided configuration as this configuration manager.- Specified by:
createChild
in classConfigurationManager
- Parameters:
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. Usenull
for the bootstrap registry.componentType
- The name of the component type to retrieve the configuration of the designated instances. Usenull
for the bootstrap registry.- Returns:
- A new configuration manager having the root and provided configuration appropriate for the designated instance or the same as this configuration manager.
- Throws:
ConfigurationException
- If the configuration for the designated instance cannot be retrieved, aConfigurationException
will be thrown.
-
newDatabaseConfiguration
public static org.apache.commons.configuration2.DatabaseConfiguration newDatabaseConfiguration(Logger logger, JDBCDataSource dataSource, String tableName, String keyColumn, String valueColumn) throws org.apache.commons.configuration2.ex.ConfigurationException, SQLException
Creates a newDatabaseConfiguration
using the designated table and columns to store the configuration in the designated data source. This also creates a table manager for creating and deleting the table appropriately.
This also registers logging errors occurring with the database configuration whereas most critical logs are problems when adding or changing properties.- Parameters:
logger
- The logger for problems creating or dropping the table.dataSource
- The datasource which stores the configuration.tableName
- The name of the table containing the configuration values.keyColumn
- The name of the column containing the configuration keys.valueColumn
- The name of the column containing the configuration values.- Returns:
- A new database configuration.
- Throws:
org.apache.commons.configuration2.ex.ConfigurationException
- If creating the configuration fails, aConfigurationException
will be thrown.SQLException
- If detecting whether the table exists or not fails, anSQLException
will be thrown.
-
-