commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1460853 - /commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/FileHandlerReloadingDetector.java
Date Mon, 25 Mar 2013 19:13:54 GMT
Author: oheger
Date: Mon Mar 25 19:13:54 2013
New Revision: 1460853

URL: http://svn.apache.org/r1460853
Log:
Made FileHandlerReloadingDetector more extensible.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/FileHandlerReloadingDetector.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/FileHandlerReloadingDetector.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/FileHandlerReloadingDetector.java?rev=1460853&r1=1460852&r2=1460853&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/FileHandlerReloadingDetector.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/reloading/FileHandlerReloadingDetector.java
Mon Mar 25 19:13:54 2013
@@ -154,17 +154,17 @@ public class FileHandlerReloadingDetecto
         {
             lastChecked = now;
 
-            File file = getExistingFile();
-            if (file != null)
+            long modified = getLastModificationDate();
+            if (modified > 0)
             {
                 if (lastModified == 0)
                 {
                     // initialization
-                    updateLastModified(file);
+                    updateLastModified(modified);
                 }
                 else
                 {
-                    if (file.lastModified() != lastModified)
+                    if (modified != lastModified)
                     {
                         return true;
                     }
@@ -182,7 +182,31 @@ public class FileHandlerReloadingDetecto
      */
     public void reloadingPerformed()
     {
-        updateLastModified(getExistingFile());
+        updateLastModified(getLastModificationDate());
+    }
+
+    /**
+     * Returns the date of the last modification of the monitored file. A return
+     * value of 0 indicates, that the monitored file does not exist.
+     *
+     * @return the last modification date
+     */
+    protected long getLastModificationDate()
+    {
+        File file = getExistingFile();
+        return (file != null) ? file.lastModified() : 0;
+    }
+
+    /**
+     * Updates the last modification date of the monitored file. The need for a
+     * reload is detected only if the file's modification date is different from
+     * this value.
+     *
+     * @param time the new last modification date
+     */
+    protected void updateLastModified(long time)
+    {
+        lastModified = time;
     }
 
     /**
@@ -217,20 +241,6 @@ public class FileHandlerReloadingDetecto
     }
 
     /**
-     * Updates the last modified field based on the given {@code File} object.
-     * The file is checked for <b>null</b>.
-     *
-     * @param file the file to be monitored
-     */
-    private void updateLastModified(File file)
-    {
-        if (file != null)
-        {
-            lastModified = file.lastModified();
-        }
-    }
-
-    /**
      * Helper method for transforming a URL into a file object. This method
      * handles file: and jar: URLs.
      *



Mime
View raw message