Class CombinedReloadingController
- java.lang.Object
-
- org.apache.commons.configuration2.reloading.ReloadingController
-
- org.apache.commons.configuration2.reloading.CombinedReloadingController
-
- All Implemented Interfaces:
EventSource
public class CombinedReloadingController extends ReloadingController
A specialized
ReloadingController
implementation which manages an arbitrary number of otherReloadingController
objects.This class can be used to handle multiple simple controllers for reload operations as a single object. As a usage example consider a combined configuration containing a number of configuration sources of which some support reloading. In this scenario all
ReloadingController
instances for the reloading-enabled sources can be added to aCombinedReloadingController
. Then by triggering the combined controller a reload check is performed on all child sources.This class is a typical implementation of the composite pattern. An instance is constructed with a collection of sub
ReloadingController
objects. Its operations are implemented by delegating to all child controllers.This class expects the managed controller objects to be passed to the constructor. From this list a defensive copy is created so that it cannot be changed later on. Derived classes can override the
getSubControllers()
method if they need another way to handle child controllers (e.g. a more dynamic way). However, they are then responsible to ensure a safe access to this list in a multi-threaded environment.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
CombinedReloadingController.MultiReloadingControllerDetector
A specialized implementation of theReloadingDetector
interface which operates on a collection ofReloadingController
objects.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Collection<ReloadingController>
controllers
The collection with managed reloading controllers.private ReloadingDetector
detector
The reloading detector used by this instance.private static ReloadingDetector
DUMMY
Constant for a dummy reloading detector.
-
Constructor Summary
Constructors Constructor Description CombinedReloadingController(java.util.Collection<? extends ReloadingController> subCtrls)
Creates a new instance ofCombinedReloadingController
and initializes it with theReloadingController
objects to be managed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.Collection<ReloadingController>
checkManagedControllers(java.util.Collection<? extends ReloadingController> subCtrls)
Checks the collection with the passed in sub controllers and creates a defensive copy.ReloadingDetector
getDetector()
Gets theReloadingDetector
used by this controller.java.util.Collection<ReloadingController>
getSubControllers()
Gets a (unmodifiable) collection with the sub controllers managed by this combined controller.void
resetInitialReloadingState()
Resets the reloading state of all managed sub controllers unconditionally.-
Methods inherited from class org.apache.commons.configuration2.reloading.ReloadingController
addEventListener, checkForReloading, isInReloadingState, removeEventListener, resetReloadingState
-
-
-
-
Field Detail
-
DUMMY
private static final ReloadingDetector DUMMY
Constant for a dummy reloading detector.
-
controllers
private final java.util.Collection<ReloadingController> controllers
The collection with managed reloading controllers.
-
detector
private final ReloadingDetector detector
The reloading detector used by this instance.
-
-
Constructor Detail
-
CombinedReloadingController
public CombinedReloadingController(java.util.Collection<? extends ReloadingController> subCtrls)
Creates a new instance ofCombinedReloadingController
and initializes it with theReloadingController
objects to be managed.- Parameters:
subCtrls
- the collection with subReloadingController
s (must not be null or contain null entries)- Throws:
java.lang.IllegalArgumentException
- if the passed in collection is null or contains null entries
-
-
Method Detail
-
checkManagedControllers
private static java.util.Collection<ReloadingController> checkManagedControllers(java.util.Collection<? extends ReloadingController> subCtrls)
Checks the collection with the passed in sub controllers and creates a defensive copy.- Parameters:
subCtrls
- the collection with sub controllers- Returns:
- a copy of the collection to be stored in the newly created instance
- Throws:
java.lang.IllegalArgumentException
- if the passed in collection is null or contains null entries
-
getDetector
public ReloadingDetector getDetector()
Gets theReloadingDetector
used by this controller. This implementation returns a special reloading detector which operates on all managed controllers.- Overrides:
getDetector
in classReloadingController
- Returns:
- the
ReloadingDetector
-
getSubControllers
public java.util.Collection<ReloadingController> getSubControllers()
Gets a (unmodifiable) collection with the sub controllers managed by this combined controller.- Returns:
- a collection with sub controllers
-
resetInitialReloadingState
public void resetInitialReloadingState()
Resets the reloading state of all managed sub controllers unconditionally. This method is intended to be called after the creation of an instance. It may be the case that some of the sub controllers are already in reloading state, so their state is out of sync with this controller's global reloading state. This method ensures that the reloading state of all sub controllers is reset.
-
-