hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r897643 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/cookie/CookieSpecRegistry.java test/java/org/apache/http/cookie/TestCookiePolicy.java
Date Sun, 10 Jan 2010 14:52:03 GMT
Author: sebb
Date: Sun Jan 10 14:52:02 2010
New Revision: 897643

URL: http://svn.apache.org/viewvc?rev=897643&view=rev
Log:
HTTPCLIENT-903 Use ConcurrentHashMap instead of [Linked]HashMap for thread-safety

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieSpecRegistry.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/cookie/TestCookiePolicy.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieSpecRegistry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieSpecRegistry.java?rev=897643&r1=897642&r2=897643&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieSpecRegistry.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/cookie/CookieSpecRegistry.java
Sun Jan 10 14:52:02 2010
@@ -28,12 +28,11 @@
 package org.apache.http.cookie;
 
 import java.util.ArrayList;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.http.annotation.GuardedBy;
 import org.apache.http.annotation.ThreadSafe;
 
 import org.apache.http.params.HttpParams;
@@ -49,12 +48,11 @@
 @ThreadSafe
 public final class CookieSpecRegistry {
 
-    @GuardedBy("this")
-    private final Map<String,CookieSpecFactory> registeredSpecs;
+    private final ConcurrentHashMap<String,CookieSpecFactory> registeredSpecs;
     
     public CookieSpecRegistry() {
         super();
-        this.registeredSpecs = new LinkedHashMap<String,CookieSpecFactory>();
+        this.registeredSpecs = new ConcurrentHashMap<String,CookieSpecFactory>();
     }
     
     /**
@@ -68,7 +66,7 @@
      * 
      * @see #getCookieSpec(String)
      */
-    public synchronized void register(final String name, final CookieSpecFactory factory)
{
+    public void register(final String name, final CookieSpecFactory factory) {
          if (name == null) {
              throw new IllegalArgumentException("Name may not be null");
          }
@@ -83,7 +81,7 @@
      * 
      * @param id the identifier of the {@link CookieSpec cookie specification} to unregister
      */
-    public synchronized void unregister(final String id) {
+    public void unregister(final String id) {
          if (id == null) {
              throw new IllegalArgumentException("Id may not be null");
          }
@@ -101,7 +99,7 @@
      * 
      * @throws IllegalStateException if a policy with the given name cannot be found
      */
-    public synchronized CookieSpec getCookieSpec(final String name, final HttpParams params)

+    public CookieSpec getCookieSpec(final String name, final HttpParams params) 
         throws IllegalStateException {
 
         if (name == null) {
@@ -124,21 +122,21 @@
      * 
      * @throws IllegalStateException if a policy with the given name cannot be found
      */
-    public synchronized CookieSpec getCookieSpec(final String name) 
+    public CookieSpec getCookieSpec(final String name) 
         throws IllegalStateException {
         return getCookieSpec(name, null);
     } 
 
     /**
-     * Obtains a list containing names of all registered {@link CookieSpec cookie 
-     * specs} in their default order.
+     * Obtains a list containing the names of all registered {@link CookieSpec cookie 
+     * specs}.
      * 
      * Note that the DEFAULT policy (if present) is likely to be the same
      * as one of the other policies, but does not have to be.
      * 
      * @return list of registered cookie spec names
      */
-    public synchronized List<String> getSpecNames(){
+    public List<String> getSpecNames(){
         return new ArrayList<String>(registeredSpecs.keySet()); 
     }
     
@@ -148,7 +146,7 @@
      * 
      * @param map cookie specs
      */
-    public synchronized void setItems(final Map<String, CookieSpecFactory> map) {
+    public void setItems(final Map<String, CookieSpecFactory> map) {
         if (map == null) {
             return;
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/cookie/TestCookiePolicy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/cookie/TestCookiePolicy.java?rev=897643&r1=897642&r2=897643&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/cookie/TestCookiePolicy.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/cookie/TestCookiePolicy.java
Sun Jan 10 14:52:02 2010
@@ -27,6 +27,7 @@
 
 package org.apache.http.cookie;
 
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 
@@ -83,9 +84,10 @@
         names = registry.getSpecNames();
         assertNotNull(names);
         assertEquals(3, names.size());
-        assertEquals(BROWSER_COMPATIBILITY.toLowerCase(Locale.ENGLISH), names.get(0));
-        assertEquals(NETSCAPE.toLowerCase(Locale.ENGLISH), names.get(1));
-        assertEquals(RFC_2109.toLowerCase(Locale.ENGLISH), names.get(2));
+        HashSet<String> m = new HashSet<String>(names);
+        assertTrue(m.contains(BROWSER_COMPATIBILITY.toLowerCase(Locale.ENGLISH)));
+        assertTrue(m.contains(NETSCAPE.toLowerCase(Locale.ENGLISH)));
+        assertTrue(m.contains(RFC_2109.toLowerCase(Locale.ENGLISH)));
 
         registry.unregister(NETSCAPE); 
         registry.unregister(NETSCAPE); 



Mime
View raw message