Package io.confound.config
Class ManagedConfiguration
- java.lang.Object
-
- io.confound.config.AbstractConfiguration
-
- io.confound.config.AbstractChildConfigurationDecorator<Configuration>
-
- io.confound.config.ManagedConfiguration
-
- All Implemented Interfaces:
Configuration
public class ManagedConfiguration extends AbstractChildConfigurationDecorator<Configuration> implements Configuration
A configuration that wraps manages a cached configuration, reloading when needed.- Author:
- Garret Wilson
-
-
Field Summary
-
Fields inherited from interface io.confound.config.Configuration
KEY_SEGMENT_SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description ManagedConfiguration(ConfigurationManager configurationManager)
Configuration manager constructor.ManagedConfiguration(ConfigurationManager configurationManager, Configuration parentConfiguration)
Configuration manager and parent configuration constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Configuration
getConfiguration()
Returns the wrapped configuration.protected ConfigurationManager
getConfigurationManager()
java.util.Optional<Configuration>
getParentConfiguration()
void
invalidate()
Invalidates the managed configuration so that it will be lazily reloaded when next requested.protected boolean
isStale(Configuration configuration)
Determines if the current configuration stale.Configuration
reload()
Reloads the managed configuration.-
Methods inherited from class io.confound.config.AbstractChildConfigurationDecorator
findBoolean, findDouble, findInt, findLong, findObject, findObject, findPath, findString, findUri, getBoolean, getDouble, getInt, getLong, getObject, getObject, getPath, getString, getUri, hasConfigurationValue
-
Methods inherited from class io.confound.config.AbstractConfiguration
or
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.confound.config.Configuration
createMissingConfigurationKeyException, findBoolean, findDouble, findInt, findLong, findObject, findObject, findPath, findString, findUri, getBoolean, getDouble, getInt, getLong, getObject, getObject, getPath, getString, getUri, hasConfigurationValue, requireConfiguration, resolvePath, subConfiguration, superConfiguration, withFallback
-
-
-
-
Constructor Detail
-
ManagedConfiguration
public ManagedConfiguration(@Nonnull ConfigurationManager configurationManager)
Configuration manager constructor.- Parameters:
configurationManager
- The manager for loading and saving the configuration.- Throws:
java.lang.NullPointerException
- if the given configuration managernull
.
-
ManagedConfiguration
public ManagedConfiguration(@Nonnull ConfigurationManager configurationManager, @Nullable Configuration parentConfiguration)
Configuration manager and parent configuration constructor.- Parameters:
configurationManager
- The manager for loading and saving the configuration.parentConfiguration
- The parent configuration to use for fallback lookup, ornull
if there is no parent configuration.- Throws:
java.lang.NullPointerException
- if the given configuration managernull
.
-
-
Method Detail
-
getConfigurationManager
protected ConfigurationManager getConfigurationManager()
- Returns:
- The associated configuration manager.
-
getParentConfiguration
public java.util.Optional<Configuration> getParentConfiguration()
- Specified by:
getParentConfiguration
in classAbstractChildConfigurationDecorator<Configuration>
- Returns:
- The parent configuration for fallback lookup.
-
isStale
protected boolean isStale(@Nullable Configuration configuration) throws java.io.IOException
Determines if the current configuration stale.This method also calls
ConfigurationManager.isStale(Configuration)
.- Parameters:
configuration
- The current configuration as last known, ornull
if the configuration is not loaded.- Returns:
true
if the given configuration is stale and needs to be reloaded.- Throws:
java.io.IOException
- if there is an I/O exception checking to see if the current configuration is stale.
-
getConfiguration
protected Configuration getConfiguration() throws ConfigurationException
Description copied from class:AbstractChildConfigurationDecorator
Returns the wrapped configuration.- Specified by:
getConfiguration
in classAbstractChildConfigurationDecorator<Configuration>
- Returns:
- The decorated configuration delegate instance.
- Throws:
ConfigurationException
- if there is an error retrieving the configuration.
-
reload
public Configuration reload() throws java.io.IOException, ConfigurationException
Reloads the managed configuration.The configuration is invalidated using
invalidate()
and the configuration manager is asked to reload the configuration.This may be called at any time to manually reload refresh the configuration information, but normally consumers never need to call this directly, as the configuration is managed automatically.
- Returns:
- The freshly reloaded configuration.
- Throws:
java.io.IOException
- if an I/O error occurs loading the configuration.ConfigurationException
- If there is invalid data or invalid state preventing the configuration from being loaded.
-
invalidate
public void invalidate()
Invalidates the managed configuration so that it will be lazily reloaded when next requested.This method additionally calls
ConfigurationManager.invalidate()
.- See Also:
ConfigurationManager.invalidate()
-
-