Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 43367 invoked from network); 25 Apr 2008 05:46:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Apr 2008 05:46:18 -0000 Received: (qmail 83160 invoked by uid 500); 25 Apr 2008 05:46:20 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 83134 invoked by uid 500); 25 Apr 2008 05:46:20 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 83119 invoked by uid 99); 25 Apr 2008 05:46:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Apr 2008 22:46:20 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Apr 2008 05:45:34 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DD0451A9832; Thu, 24 Apr 2008 22:45:53 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@harmony.apache.org From: ndbeyer@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080425054553.DD0451A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 negCache; + private static NegativeCache 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