You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2013/01/20 18:09:15 UTC
svn commit: r1435890 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java
test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java
Author: oheger
Date: Sun Jan 20 17:09:15 2013
New Revision: 1435890
URL: http://svn.apache.org/viewvc?rev=1435890&view=rev
Log:
Made CombinedReloadingController more extensible regarding the source of managed controllers.
After recent change on ReloadingController, there is no need to test for the reloading state explicitly.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java?rev=1435890&r1=1435889&r2=1435890&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/CombinedReloadingController.java Sun Jan 20 17:09:15 2013
@@ -40,12 +40,30 @@ import java.util.Collections;
* objects. Its operations are implemented by delegating to all child
* controllers.
* </p>
+ * <p>
+ * 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
+ * {@link #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.
+ * </p>
*
* @version $Id$
* @since 2.0
*/
public class CombinedReloadingController extends ReloadingController
{
+ /** Constant for a dummy reloading detector. */
+ private static final ReloadingDetector DUMMY =
+ new MultiReloadingControllerDetector(null);
+
+ /** The collection with managed reloading controllers. */
+ private final Collection<ReloadingController> controllers;
+
+ /** The reloading detector used by this instance. */
+ private final ReloadingDetector detector;
+
/**
* Creates a new instance of {@code CombinedReloadingController} and
* initializes it with the {@code ReloadingController} objects to be
@@ -59,7 +77,9 @@ public class CombinedReloadingController
public CombinedReloadingController(
Collection<? extends ReloadingController> subCtrls)
{
- super(createDetector(subCtrls));
+ super(DUMMY);
+ controllers = checkManagedControllers(subCtrls);
+ detector = new MultiReloadingControllerDetector(this);
}
/**
@@ -70,22 +90,30 @@ public class CombinedReloadingController
*/
public Collection<ReloadingController> getSubControllers()
{
- return ((MultiReloadingControllerDetector) getDetector())
- .getControllers();
+ return controllers;
}
/**
- * Creates a specialized detector object which manages the passed in sub
- * controllers. The collection with controllers is also checked for
- * validity.
+ * {@inheritDoc} This implementation returns a special reloading detector
+ * which operates on all managed controllers.
+ */
+ @Override
+ public ReloadingDetector getDetector()
+ {
+ return detector;
+ }
+
+ /**
+ * Checks the collection with the passed in sub controllers and creates a
+ * defensive copy.
*
* @param subCtrls the collection with sub controllers
- * @return the {@code ReloadingDetector} to be used by the combined
- * controller
+ * @return a copy of the collection to be stored in the newly created
+ * instance
* @throws IllegalArgumentException if the passed in collection is
* <b>null</b> or contains <b>null</b> entries
*/
- private static ReloadingDetector createDetector(
+ private static Collection<ReloadingController> checkManagedControllers(
Collection<? extends ReloadingController> subCtrls)
{
if (subCtrls == null)
@@ -104,8 +132,7 @@ public class CombinedReloadingController
}
}
- return new MultiReloadingControllerDetector(
- Collections.unmodifiableCollection(ctrls));
+ return Collections.unmodifiableCollection(ctrls);
}
/**
@@ -117,19 +144,17 @@ public class CombinedReloadingController
private static class MultiReloadingControllerDetector implements
ReloadingDetector
{
- /** Stores the managed sub controllers. */
- private final Collection<ReloadingController> controllers;
+ /** A reference to the owning combined reloading controller. */
+ private final CombinedReloadingController owner;
/**
- * Creates a new instance of {@code MultiReloadingControllerDetector}
- * and sets the managed controllers.
+ * Creates a new instance of {@code MultiReloadingControllerDetector}.
*
- * @param ctrls a collection with the managed controllers
+ * @param o the owner
*/
- public MultiReloadingControllerDetector(
- Collection<ReloadingController> ctrls)
+ public MultiReloadingControllerDetector(CombinedReloadingController o)
{
- controllers = ctrls;
+ owner = o;
}
/**
@@ -139,9 +164,9 @@ public class CombinedReloadingController
*/
public boolean isReloadingRequired()
{
- for (ReloadingController rc : getControllers())
+ for (ReloadingController rc : owner.getSubControllers())
{
- if (rc.checkForReloading(null) || rc.isInReloadingState())
+ if (rc.checkForReloading(null))
{
return true;
}
@@ -155,20 +180,10 @@ public class CombinedReloadingController
*/
public void reloadingPerformed()
{
- for (ReloadingController rc : getControllers())
+ for (ReloadingController rc : owner.getSubControllers())
{
rc.resetReloadingState();
}
}
-
- /**
- * Returns the collection with managed sub controllers.
- *
- * @return the controllers the sub controllers
- */
- Collection<ReloadingController> getControllers()
- {
- return controllers;
- }
}
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java?rev=1435890&r1=1435889&r2=1435890&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/reloading/TestCombinedReloadingController.java Sun Jan 20 17:09:15 2013
@@ -116,8 +116,6 @@ public class TestCombinedReloadingContro
CombinedReloadingController ctrl = setUpController();
EasyMock.expect(subControllers[0].checkForReloading(null)).andReturn(
Boolean.FALSE);
- EasyMock.expect(subControllers[0].isInReloadingState()).andReturn(
- Boolean.FALSE);
EasyMock.expect(subControllers[1].checkForReloading(null)).andReturn(
Boolean.TRUE);
replaySubControllers();
@@ -126,23 +124,6 @@ public class TestCombinedReloadingContro
}
/**
- * Tests a reloading check if a sub controller is already in reloading
- * state.
- */
- @Test
- public void testCheckForReloadingTrueAlreadyInReloadingState()
- {
- CombinedReloadingController ctrl = setUpController();
- EasyMock.expect(subControllers[0].checkForReloading(null)).andReturn(
- Boolean.FALSE);
- EasyMock.expect(subControllers[0].isInReloadingState()).andReturn(
- Boolean.TRUE);
- replaySubControllers();
- assertTrue("Wrong result", ctrl.checkForReloading("someData"));
- verifySubSontrollers();
- }
-
- /**
* Tests a check for a reloading operation which results in false.
*/
@Test
@@ -153,7 +134,6 @@ public class TestCombinedReloadingContro
{
EasyMock.expect(rc.checkForReloading(null))
.andReturn(Boolean.FALSE);
- EasyMock.expect(rc.isInReloadingState()).andReturn(Boolean.FALSE);
}
replaySubControllers();
assertFalse("Wrong result", ctrl.checkForReloading("someParam"));