Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 42305F0A9 for ; Tue, 26 Mar 2013 15:12:10 +0000 (UTC) Received: (qmail 89961 invoked by uid 500); 26 Mar 2013 15:12:10 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 89921 invoked by uid 500); 26 Mar 2013 15:12:10 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 89912 invoked by uid 99); 26 Mar 2013 15:12:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Mar 2013 15:12:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Mar 2013 15:12:08 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6165F2388A9C; Tue, 26 Mar 2013 15:11:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1461176 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/ test/java/org/apache/commons/configuration/builder/ Date: Tue, 26 Mar 2013 15:11:48 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130326151148.6165F2388A9C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Tue Mar 26 15:11:47 2013 New Revision: 1461176 URL: http://svn.apache.org/r1461176 Log: ReloadingFileBasedConfigurationBuilder now evaluates the reloadingDetectorFactory property in its parameters. This makes it possible to specify a custom ReloadingDetectoryFactory, so that different reloading strategies can be used. Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ReloadingFileBasedConfigurationBuilder.java commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestReloadingFileBasedConfigurationBuilder.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ReloadingFileBasedConfigurationBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ReloadingFileBasedConfigurationBuilder.java?rev=1461176&r1=1461175&r2=1461176&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ReloadingFileBasedConfigurationBuilder.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/ReloadingFileBasedConfigurationBuilder.java Tue Mar 26 15:11:47 2013 @@ -65,6 +65,10 @@ import org.apache.commons.configuration. public class ReloadingFileBasedConfigurationBuilder extends FileBasedConfigurationBuilder implements ReloadingControllerSupport { + /** The default factory for creating reloading detector objects. */ + private static final ReloadingDetectorFactory DEFAULT_DETECTOR_FACTORY = + new DefaultReloadingDetectorFactory(); + /** The reloading controller associated with this object. */ private final ReloadingController reloadingController; @@ -139,21 +143,23 @@ public class ReloadingFileBasedConfigura /** * Creates a {@code ReloadingDetector} which monitors the passed in * {@code FileHandler}. This method is called each time a new result object - * is created with the current {@code FileHandler}. The - * {@code ReloadingDetector} associated with this builder's - * {@link ReloadingController} delegates to this object. This implementation - * returns a new {@code FileHandlerReloadingDetector} object. Note: This - * method is called from a synchronized block. + * is created with the current {@code FileHandler}. This implementation + * checks whether a {@code ReloadingDetectorFactory} is specified in the + * current parameters. If this is the case, it is invoked. Otherwise, a + * default factory is used to create a {@code FileHandlerReloadingDetector} + * object. Note: This method is called from a synchronized block. * * @param handler the current {@code FileHandler} * @param fbparams the object with parameters related to file-based builders * @return a {@code ReloadingDetector} for this {@code FileHandler} + * @throws ConfigurationException if an error occurs */ protected ReloadingDetector createReloadingDetector(FileHandler handler, FileBasedBuilderParametersImpl fbparams) + throws ConfigurationException { - return new FileHandlerReloadingDetector(handler, - fbparams.getReloadingRefreshDelay()); + return fetchDetectorFactory(fbparams).createReloadingDetector(handler, + fbparams); } /** @@ -243,4 +249,18 @@ public class ReloadingFileBasedConfigura } }; } + + /** + * Returns a {@code ReloadingDetectorFactory} either from the passed in + * parameters or a default factory. + * + * @param params the current parameters object + * @return the {@code ReloadingDetectorFactory} to be used + */ + private static ReloadingDetectorFactory fetchDetectorFactory( + FileBasedBuilderParametersImpl params) + { + ReloadingDetectorFactory factory = params.getReloadingDetectorFactory(); + return (factory != null) ? factory : DEFAULT_DETECTOR_FACTORY; + } } Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestReloadingFileBasedConfigurationBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestReloadingFileBasedConfigurationBuilder.java?rev=1461176&r1=1461175&r2=1461176&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestReloadingFileBasedConfigurationBuilder.java (original) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestReloadingFileBasedConfigurationBuilder.java Tue Mar 26 15:11:47 2013 @@ -58,10 +58,11 @@ public class TestReloadingFileBasedConfi } /** - * Tests whether a correct reloading detector is created. + * Tests whether a correct reloading detector is created if no custom factory + * was set. */ @Test - public void testCreateReloadingDetector() + public void testCreateReloadingDetectorDefaultFactory() throws ConfigurationException { ReloadingFileBasedConfigurationBuilder builder = new ReloadingFileBasedConfigurationBuilder( @@ -79,6 +80,32 @@ public class TestReloadingFileBasedConfi } /** + * Tests whether a custom reloading detector factory can be installed. + */ + @Test + public void testCreateReloadingDetectoryCustomFactory() + throws ConfigurationException + { + ReloadingDetector detector = + EasyMock.createMock(ReloadingDetector.class); + ReloadingDetectorFactory factory = + EasyMock.createMock(ReloadingDetectorFactory.class); + FileHandler handler = new FileHandler(); + FileBasedBuilderParametersImpl params = + new FileBasedBuilderParametersImpl(); + EasyMock.expect(factory.createReloadingDetector(handler, params)) + .andReturn(detector); + EasyMock.replay(detector, factory); + params.setReloadingDetectorFactory(factory); + ReloadingFileBasedConfigurationBuilder builder = + new ReloadingFileBasedConfigurationBuilder( + PropertiesConfiguration.class); + assertSame("Wrong detector", detector, + builder.createReloadingDetector(handler, params)); + EasyMock.verify(factory); + } + + /** * Tests the isReloadingRequired() implementation of the detector associated * with the reloading controller. */