Package io.confound.config
Class ManagedConfiguration
- java.lang.Object
-
- io.confound.config.AbstractParametersDecorator
-
- io.confound.config.ManagedConfiguration
-
- All Implemented Interfaces:
Configuration
,Parameters
public class ManagedConfiguration extends AbstractParametersDecorator implements Configuration
A configuration that wraps manages a cached configuration, reloading when needed.- Author:
- Garret Wilson
-
-
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 ConfigurationManager
getConfigurationManager()
protected Parameters
getParameters()
Returns the wrapped parameters.java.util.Optional<Configuration>
getParentConfiguration()
void
invalidate()
Invalidates the managed configuration so that it will be lazily reloaded when next requested.protected boolean
isStale(Parameters parameters)
Determines if the current configuration stale.Configuration
reload()
Reloads the managed configuration.-
Methods inherited from class io.confound.config.AbstractParametersDecorator
getOptionalBoolean, getOptionalDouble, getOptionalInt, getOptionalLong, getOptionalParameter, getOptionalPath, getOptionalString, getOptionalUri, hasParameter
-
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
hasParameter
-
Methods inherited from interface io.confound.config.Parameters
getBoolean, getDouble, getInt, getLong, getOptionalBoolean, getOptionalDouble, getOptionalInt, getOptionalLong, getOptionalParameter, getOptionalPath, getOptionalString, getOptionalUri, getParameter, getPath, getString, getUri, requireParameter, resolvePath
-
-
-
-
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 interfaceConfiguration
- Returns:
- The parent configuration for fallback lookup.
-
isStale
protected boolean isStale(@Nullable Parameters parameters) throws java.io.IOException
Determines if the current configuration stale.This method also calls
ConfigurationManager.isStale(Parameters)
.- Parameters:
parameters
- The current parameters as last known, ornull
if the configuration is not loaded.- Returns:
true
if the given parameters are stale and need to be reloaded.- Throws:
java.io.IOException
- if there is an I/O exception checking to see if the current configuration is stale.
-
getParameters
protected Parameters getParameters() throws ConfigurationException
Description copied from class:AbstractParametersDecorator
Returns the wrapped parameters.- Specified by:
getParameters
in classAbstractParametersDecorator
- Returns:
- The decorated parameters delegate instance.
- Throws:
ConfigurationException
- if there is an error retrieving the parameters.
-
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()
-
-