Class ReloadingCombinedConfigurationBuilder
java.lang.Object
org.apache.commons.configuration2.builder.BasicConfigurationBuilder<CombinedConfiguration>
org.apache.commons.configuration2.builder.combined.CombinedConfigurationBuilder
org.apache.commons.configuration2.builder.combined.ReloadingCombinedConfigurationBuilder
- All Implemented Interfaces:
ConfigurationBuilder<CombinedConfiguration>
,EventSource
,ReloadingControllerSupport
public class ReloadingCombinedConfigurationBuilder
extends CombinedConfigurationBuilder
implements ReloadingControllerSupport
An extension of CombinedConfigurationBuilder
which also supports reloading operations.
This class differs from its super class in the following aspects:
- A
ReloadingController
is created which manages all child configuration builders supporting reloading operations. - If no
ConfigurationBuilder
is provided for the definition configuration, a builder with reloading support is created.
This class can be used exactly as its super class for creating combined configurations from multiple configuration sources. In addition, the combined reloading controller managed by an instance can be used to react on changes in one of these configuration sources or in the definition configuration.
- Since:
- 2.0
-
Field Summary
Fields inherited from class org.apache.commons.configuration2.builder.combined.CombinedConfigurationBuilder
ADDITIONAL_NAME
-
Constructor Summary
ConstructorDescriptionCreates a new instance ofReloadingCombinedConfigurationBuilder
.Creates a new instance ofReloadingCombinedConfigurationBuilder
and sets the specified initialization parameters.ReloadingCombinedConfigurationBuilder
(Map<String, Object> params, boolean allowFailOnInit) Creates a new instance ofReloadingCombinedConfigurationBuilder
and sets the specified initialization parameters and the allowFailOnInit flag. -
Method Summary
Modifier and TypeMethodDescriptionconfigure
(BuilderParameters... params) Appends the content of the specifiedBuilderParameters
objects to the current initialization parameters.protected ReloadingController
Creates theReloadingController
for this builder.protected ConfigurationBuilder<? extends HierarchicalConfiguration<?>>
createXMLDefinitionBuilder
(BuilderParameters builderParams) Creates a default builder for the definition configuration and initializes it with a parameters object.Gets the configuration provided by this builder.Gets theReloadingController
associated with this object.protected void
Initializes a newly created result object.static void
obtainReloadingController
(Collection<ReloadingController> subControllers, Object builder) Checks whether the passed in builder object supports reloading.Methods inherited from class org.apache.commons.configuration2.builder.combined.CombinedConfigurationBuilder
builderNames, configureEntityResolver, createAdditionalsConfiguration, createResultDeclaration, getChildBuilders, getDefinitionBuilder, getDefinitionConfiguration, getNamedBuilder, initChildBuilderParameters, initFileSystem, initSystemProperties, providerForTag, registerConfiguredLookups, resetParameters, setupDefinitionBuilder
Methods inherited from class org.apache.commons.configuration2.builder.BasicConfigurationBuilder
addEventListener, addParameters, connectToReloadingController, copyEventListeners, copyEventListeners, createResult, createResultInstance, fetchBeanHelper, fireBuilderEvent, getParameters, getResultClass, getResultDeclaration, installEventListener, isAllowFailOnInit, removeEventListener, reset, resetResult, setParameters
-
Constructor Details
-
ReloadingCombinedConfigurationBuilder
Creates a new instance ofReloadingCombinedConfigurationBuilder
. No parameters are set. -
ReloadingCombinedConfigurationBuilder
Creates a new instance ofReloadingCombinedConfigurationBuilder
and sets the specified initialization parameters.- Parameters:
params
- a map with initialization parameters
-
ReloadingCombinedConfigurationBuilder
Creates a new instance ofReloadingCombinedConfigurationBuilder
and sets the specified initialization parameters and the allowFailOnInit flag.- Parameters:
params
- a map with initialization parametersallowFailOnInit
- the allowFailOnInit flag
-
-
Method Details
-
obtainReloadingController
public static void obtainReloadingController(Collection<ReloadingController> subControllers, Object builder) Checks whether the passed in builder object supports reloading. If yes, its reloading controller is obtained and added to the given list.- Parameters:
subControllers
- the list with sub controllersbuilder
- the builder object to be checked
-
configure
Appends the content of the specifiedBuilderParameters
objects to the current initialization parameters. Calling this method multiple times will create a union of the parameters provided. This method is overridden to adapt the return type. This method is overridden to adapt the return type.- Overrides:
configure
in classCombinedConfigurationBuilder
- Parameters:
params
- an arbitrary number of objects with builder parameters- Returns:
- a reference to this builder for method chaining
-
createReloadingController
Creates theReloadingController
for this builder. This method is called after the result configuration has been created and initialized. It is called from a synchronized block. This implementation creates aCombinedReloadingController
.- Returns:
- the
ReloadingController
for this builder - Throws:
ConfigurationException
- if an error occurs
-
createXMLDefinitionBuilder
protected ConfigurationBuilder<? extends HierarchicalConfiguration<?>> createXMLDefinitionBuilder(BuilderParameters builderParams) Creates a default builder for the definition configuration and initializes it with a parameters object. This method is called if no definition builder is defined in this builder's parameters. This implementation creates a default file-based builder which produces anXMLConfiguration
; it expects a corresponding file specification. Note: This method is called in a synchronized block. This implementation creates a builder for XML configurations with reloading support.- Overrides:
createXMLDefinitionBuilder
in classCombinedConfigurationBuilder
- Parameters:
builderParams
- the parameters object for the builder- Returns:
- the standard builder for the definition configuration
-
getConfiguration
Gets the configuration provided by this builder. An implementation has to perform all necessary steps for creating and initializing aImmutableConfiguration
object. This implementation creates the result configuration on first access. Later invocations return the same object until this builder is reset. The double-check idiom for lazy initialization is used (Bloch, Effective Java, item 71). This implementation makes sure that the reloading state of the managed reloading controller is reset. Note that this has to be done here and not ininitResultInstance(CombinedConfiguration)
because it must be outside of a synchronized block; otherwise, a dead-lock situation can occur.- Specified by:
getConfiguration
in interfaceConfigurationBuilder<CombinedConfiguration>
- Overrides:
getConfiguration
in classBasicConfigurationBuilder<CombinedConfiguration>
- Returns:
- the configuration
- Throws:
ConfigurationException
- if an error occurs
-
getReloadingController
Gets theReloadingController
associated with this object. This implementation returns aCombinedReloadingController
which contains sub controllers for all child configuration sources with reloading support. If the definition builder supports reloading, its controller is contained, too. Note that the combined reloading controller is initialized when the result configuration is created (i.e. when callinggetConfiguration()
for the first time). So this method does not return a meaningful result before.- Specified by:
getReloadingController
in interfaceReloadingControllerSupport
- Returns:
- the associated
ReloadingController
-
initResultInstance
Initializes a newly created result object. This is the second step of the process of producing a result object for this builder. This implementation uses theBeanHelper
class to initialize the object's property based on theBeanDeclaration
returned byBasicConfigurationBuilder.getResultDeclaration()
. Note: This method is invoked in a synchronized block. This is required because internal state is accessed. Sub classes must not call this method without proper synchronization. This implementation processes the definition configuration in order to- initialize the resulting
CombinedConfiguration
- determine the builders for all configuration sources
- populate the resulting
CombinedConfiguration
CombinedReloadingController
for all child configuration sources with reloading support.- Overrides:
initResultInstance
in classCombinedConfigurationBuilder
- Parameters:
result
- the object to be initialized- Throws:
ConfigurationException
- if an error occurs
- initialize the resulting
-