harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From regi...@apache.org
Subject svn commit: r1035930 - /harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
Date Wed, 17 Nov 2010 06:44:11 GMT
Author: regisxu
Date: Wed Nov 17 06:44:11 2010
New Revision: 1035930

URL: http://svn.apache.org/viewvc?rev=1035930&view=rev
Log:
Fix for HARMONY-6675: Reducing timeout value in CanonicalPatchCache to fix a file not found
error in Hadoop common

1. make timeout of CanonicalPatchCache configurable via property
   'org.apache.harmony.file.canonical.path.cache.timeout'.
2. reduce default timeout value to 30 seconds.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java?rev=1035930&r1=1035929&r2=1035930&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/io/FileCanonPathCache.java
Wed Nov 17 06:44:11 2010
@@ -55,9 +55,29 @@ public class FileCanonPathCache {
     private static Object lock = new Object();
 
     /**
-     * Expired time.
+     * Expired time, 0 disable this cache.
      */
-    private static long timeout = 600000;
+    private static long timeout = 30000;
+
+    /**
+     * Whether to enable this cache.
+     */
+    private static boolean isEnable = true;
+
+    public static final String FILE_CANONICAL_PATH_CACHE_TIMEOUT = "org.apache.harmony.file.canonical.path.cache.timeout";
+
+    static {
+        String value = System.getProperty(FILE_CANONICAL_PATH_CACHE_TIMEOUT);
+        try {
+            timeout = Long.parseLong(value);
+        } catch (NumberFormatException e) {
+            // use default timeout value
+        }
+
+        if (timeout <= 0) {
+            isEnable = false;
+        }
+    }
 
     /**
      * Retrieve element from cache.
@@ -68,6 +88,10 @@ public class FileCanonPathCache {
      * 
      */
     public static String get(String path) {
+        if (!isEnable) {
+            return null;
+        }
+
         CacheElement element = null;
         synchronized (lock) {
             element = cache.get(path);
@@ -104,6 +128,10 @@ public class FileCanonPathCache {
      *            the canonical path of <code>path</code>.
      */
     public static void put(String path, String canonicalPath) {
+        if (!isEnable) {
+            return;
+        }
+
         CacheElement element = new CacheElement(canonicalPath);
         synchronized (lock) {
             if (cache.size() >= CACHE_SIZE) {
@@ -120,6 +148,10 @@ public class FileCanonPathCache {
      * Remove all elements from cache.
      */
     public static void clear() {
+        if (!isEnable) {
+            return;
+        }
+
         synchronized (lock) {
             cache.clear();
             list.clear();
@@ -132,5 +164,9 @@ public class FileCanonPathCache {
 
     public static void setTimeout(long timeout) {
         FileCanonPathCache.timeout = timeout;
+        if (timeout <= 0) {
+            clear();
+            isEnable = false;
+        }
     }
 }



Mime
View raw message