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/03/26 16:11:15 UTC
svn commit: r1461171 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java
test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java
Author: oheger
Date: Tue Mar 26 15:11:15 2013
New Revision: 1461171
URL: http://svn.apache.org/r1461171
Log:
Added a default implementation of ReloadingDetectorFactory which creates
FileHandlerReloadingDetector objects.
Added:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java
Added: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java?rev=1461171&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java (added)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java Tue Mar 26 15:11:15 2013
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.io.FileHandler;
+import org.apache.commons.configuration.reloading.FileHandlerReloadingDetector;
+import org.apache.commons.configuration.reloading.ReloadingDetector;
+
+/**
+ * <p>
+ * A default implementation of the {@code ReloadingDetectorFactory} interface.
+ * </p>
+ * <p>
+ * This factory creates objects of type {@link FileHandlerReloadingDetector}.
+ * Instances have no state and can be shared between multiple builders.
+ * </p>
+ *
+ * @version $Id: $
+ * @since 2.0
+ */
+public class DefaultReloadingDetectorFactory implements
+ ReloadingDetectorFactory
+{
+ public ReloadingDetector createReloadingDetector(FileHandler handler,
+ FileBasedBuilderParametersImpl params)
+ throws ConfigurationException
+ {
+ return new FileHandlerReloadingDetector(handler,
+ params.getReloadingRefreshDelay());
+ }
+}
Added: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java?rev=1461171&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java (added)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java Tue Mar 26 15:11:15 2013
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.configuration.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.io.FileHandler;
+import org.apache.commons.configuration.reloading.FileHandlerReloadingDetector;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class for {@code DefaultReloadingDetectorFactory}.
+ *
+ * @version $Id: $
+ */
+public class TestDefaultReloadingDetectorFactory
+{
+ /** The factory to be tested. */
+ private DefaultReloadingDetectorFactory factory;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ factory = new DefaultReloadingDetectorFactory();
+ }
+
+ /**
+ * Tests whether a reloading detector is created correctly.
+ */
+ @Test
+ public void testCreateReloadingDetector() throws ConfigurationException
+ {
+ FileHandler handler = new FileHandler();
+ FileBasedBuilderParametersImpl params =
+ new FileBasedBuilderParametersImpl();
+ final long refreshDelay = 10000L;
+ params.setReloadingRefreshDelay(refreshDelay);
+ FileHandlerReloadingDetector detector =
+ (FileHandlerReloadingDetector) factory.createReloadingDetector(
+ handler, params);
+ assertSame("Wrong file handler", handler, detector.getFileHandler());
+ assertEquals("Wrong refresh delay", refreshDelay,
+ detector.getRefreshDelay());
+ }
+}