Class UrlConfigurationManager

    • 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 be null meaning that the global 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 no global 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 new UrlConfigurationManager 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 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.
        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,
        a ConfigurationException will be thrown.
      • UrlConfigurationManager

        protected UrlConfigurationManager​(org.apache.commons.configuration2.Configuration rootConfiguration,
                                          org.apache.commons.configuration2.Configuration providedConfiguration,
                                          UrlConfigurationManager parent)
        Creates a new UrlConfigurationManager having the designated root and provided configuration and the fields of the designated UrlConfigurationManager.
        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 designated UrlConfigurationManager.
        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 UrlConfigurationManager.
        parent - The parent UrlConfigurationManager 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 retrieving JDBCDataSources 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 the JDBCDataSources from.
        sessionFactory - The session factory to retrieve the JDBCDataSources with.
        uris - The URIs for the session tokens to retrieve the JDBCDataSources 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 class ConfigurationManager
        Parameters:
        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.
        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,
        a 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 a 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.
        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 class ConfigurationManager
        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, a ConfigurationException 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,
        a 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,
        a 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,
        a 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,
        a 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 is 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.
        Specified by:
        createChild in class ConfigurationManager
        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. 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.
        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, a ConfigurationException 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 new DatabaseConfiguration 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, a ConfigurationException will be thrown.
        SQLException - If detecting whether the table exists or not fails, an SQLException will be thrown.