harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r651493 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net: InetAddress.java NegCacheElement.java NegativeCache.java
Date Fri, 25 Apr 2008 05:45:52 GMT
Author: ndbeyer
Date: Thu Apr 24 22:45:48 2008
New Revision: 651493

URL: http://svn.apache.org/viewvc?rev=651493&view=rev
Log:
Broad swipe to make InetAddress caching thread-safe; need to come back and combine the caching
code and optimize the code paths

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegCacheElement.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java?rev=651493&r1=651492&r2=651493&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/InetAddress.java Thu
Apr 24 22:45:48 2008
@@ -403,6 +403,8 @@
             return element.inetAddress();
         }
 
+        // TODO Clean up NegativeCache; there's no need to maintain the failure message
+        
         // now try the negative cache
         String failedMessage = NegativeCache.getFailedMessage(host);
         if (failedMessage != null) {
@@ -509,11 +511,11 @@
     }
 
     class CacheElement {
-        long timeAdded = System.currentTimeMillis();
+        final long timeAdded = System.currentTimeMillis();
 
         CacheElement next;
 
-        public CacheElement() {
+        CacheElement() {
             super();
         }
 
@@ -527,18 +529,18 @@
     }
 
     static class Cache {
-        static int maxSize = 5;
+        private static int maxSize = 5;
 
         private static int size = 0;
 
         private static CacheElement head;
 
-        static void clear() {
+        static synchronized void clear() {
             size = 0;
             head = null;
         }
 
-        static void add(InetAddress value) {
+        static synchronized void add(InetAddress value) {
             CacheElement newElement = value.cacheElement();
             if (size < maxSize) {
                 size++;
@@ -549,7 +551,7 @@
             head = newElement;
         }
 
-        static CacheElement get(String name) {
+        static synchronized CacheElement get(String name) {
             CacheElement previous = null;
             CacheElement current = head;
             boolean notFound = true;
@@ -565,7 +567,7 @@
             return current;
         }
 
-        private static void deleteTail() {
+        private synchronized static void deleteTail() {
             if (0 == size) {
                 return;
             }
@@ -582,7 +584,7 @@
             previous.next = null;
         }
 
-        private static void moveToHead(CacheElement element,
+        private synchronized static void moveToHead(CacheElement element,
                 CacheElement elementPredecessor) {
             if (null == elementPredecessor) {
                 head = element;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegCacheElement.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegCacheElement.java?rev=651493&r1=651492&r2=651493&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegCacheElement.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegCacheElement.java
Thu Apr 24 22:45:48 2008
@@ -22,17 +22,10 @@
 class NegCacheElement {
 
     // we need the time to figure out when the entry is stale
-    long timeAdded = System.currentTimeMillis();
+    final long timeAdded = System.currentTimeMillis();
 
     // holds the name of the host for which the lookup failed
-    String hostName;
-
-    /**
-     * default constructor
-     */
-    public NegCacheElement() {
-        super();
-    }
+    final String hostName;
 
     /**
      * Constructor used to set the hostname for the failed entry
@@ -40,16 +33,7 @@
      * @param hostName
      *            name of the host on which the lookup failed
      */
-    public NegCacheElement(String hostName) {
+    NegCacheElement(String hostName) {
         this.hostName = hostName;
-    }
-
-    /**
-     * Answers the hostname for the cache element
-     * 
-     * @return hostName name of the host on which the lookup failed
-     */
-    String hostName() {
-        return hostName;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java?rev=651493&r1=651492&r2=651493&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/NegativeCache.java
Thu Apr 24 22:45:48 2008
@@ -29,13 +29,13 @@
 
     private static final long serialVersionUID = 1L;
 
-    static NegativeCache<String, NegCacheElement> negCache;
+    private static NegativeCache<String, NegCacheElement> negCache;
 
     // maximum number of entries in the cache
-    static final int MAX_NEGATIVE_ENTRIES = 5;
+    private static final int MAX_NEGATIVE_ENTRIES = 5;
 
     // the loading for the cache
-    static final float LOADING = 0.75F;
+    private static final float LOADING = 0.75F;
 
     /**
      * Answers the hostname for the cache element
@@ -69,7 +69,7 @@
      * @param failedMessage
      *            the message returned when we failed the lookup
      */
-    static void put(String hostName, String failedMessage) {
+    static synchronized void put(String hostName, String failedMessage) {
         checkCacheExists();
         negCache.put(hostName, new NegCacheElement(failedMessage));
     }
@@ -83,7 +83,7 @@
      * @return the message which was returned when the host failed to be looked
      *         up if there is still a valid entry within the cache
      */
-    static String getFailedMessage(String hostName) {
+    static synchronized String getFailedMessage(String hostName) {
         checkCacheExists();
         NegCacheElement element = negCache.get(hostName);
         if (element != null) {
@@ -111,7 +111,7 @@
             }
         }
         if (element != null) {
-            return element.hostName();
+            return element.hostName;
         }
         return null;
     }
@@ -119,7 +119,7 @@
     /**
      * This method checks if we have created the cache and if not creates it
      */
-    static void checkCacheExists() {
+    static synchronized void checkCacheExists() {
         if (negCache == null) {
             /*
              * Create with the access order set so ordering is based on when the



Mime
View raw message