hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r897641 - in /httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http: auth/AuthSchemeRegistry.java conn/params/ConnPerRouteBean.java conn/scheme/SchemeRegistry.java
Date Sun, 10 Jan 2010 14:23:56 GMT
Author: sebb
Date: Sun Jan 10 14:23:56 2010
New Revision: 897641

URL: http://svn.apache.org/viewvc?rev=897641&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/auth/AuthSchemeRegistry.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeRegistry.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthSchemeRegistry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthSchemeRegistry.java?rev=897641&r1=897640&r2=897641&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthSchemeRegistry.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/auth/AuthSchemeRegistry.java
Sun Jan 10 14:23:56 2010
@@ -27,12 +27,11 @@
 package org.apache.http.auth;
 
 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;
@@ -46,12 +45,11 @@
 @ThreadSafe
 public final class AuthSchemeRegistry {
 
-    @GuardedBy("this")
-    private final Map<String,AuthSchemeFactory> registeredSchemes;
+    private final ConcurrentHashMap<String,AuthSchemeFactory> registeredSchemes;
     
     public AuthSchemeRegistry() {
         super();
-        this.registeredSchemes = new LinkedHashMap<String,AuthSchemeFactory>();
+        this.registeredSchemes = new ConcurrentHashMap<String,AuthSchemeFactory>();
     }
     
     /**
@@ -69,7 +67,7 @@
      * 
      * @see #getAuthScheme
      */
-    public synchronized void register(
+    public void register(
             final String name, 
             final AuthSchemeFactory factory) {
          if (name == null) {
@@ -87,7 +85,7 @@
      * 
      * @param name the identifier of the class to unregister
      */
-    public synchronized void unregister(final String name) {
+    public void unregister(final String name) {
          if (name == null) {
              throw new IllegalArgumentException("Name may not be null");
          }
@@ -105,7 +103,7 @@
      * 
      * @throws IllegalStateException if a scheme with the given name cannot be found
      */
-    public synchronized AuthScheme getAuthScheme(final String name, final HttpParams params)

+    public AuthScheme getAuthScheme(final String name, final HttpParams params) 
         throws IllegalStateException {
 
         if (name == null) {
@@ -120,12 +118,12 @@
     } 
 
     /**
-     * Obtains a list containing names of all registered {@link AuthScheme authentication

-     * schemes} in their default order.
+     * Obtains a list containing the names of all registered {@link AuthScheme authentication

+     * schemes}
      * 
      * @return list of registered scheme names
      */
-    public synchronized List<String> getSchemeNames() {
+    public List<String> getSchemeNames() {
         return new ArrayList<String>(registeredSchemes.keySet()); 
     } 
  
@@ -135,7 +133,7 @@
      * 
      * @param map authentication schemes
      */
-    public synchronized void setItems(final Map<String, AuthSchemeFactory> map) {
+    public void setItems(final Map<String, AuthSchemeFactory> map) {
         if (map == null) {
             return;
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java?rev=897641&r1=897640&r2=897641&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java
Sun Jan 10 14:23:56 2010
@@ -26,10 +26,9 @@
 
 package org.apache.http.conn.params;
 
-import java.util.HashMap;
 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.conn.routing.HttpRoute;
@@ -48,15 +47,13 @@
     /** The default maximum number of connections allowed per host */
     public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 2;   // Per RFC 2616 sec
8.1.4
     
-    @GuardedBy("this")
-    private final Map<HttpRoute, Integer> maxPerHostMap;
+    private final ConcurrentHashMap<HttpRoute, Integer> maxPerHostMap;
     
-    @GuardedBy("this")
-    private int defaultMax;
+    private volatile int defaultMax;
     
     public ConnPerRouteBean(int defaultMax) {
         super();
-        this.maxPerHostMap = new HashMap<HttpRoute, Integer>();
+        this.maxPerHostMap = new ConcurrentHashMap<HttpRoute, Integer>();
         setDefaultMaxPerRoute(defaultMax);
     }
     
@@ -65,18 +62,18 @@
     }
     
     @Deprecated
-    public synchronized int getDefaultMax() {
+    public int getDefaultMax() {
         return this.defaultMax;
     }
 
     /**
      * @since 4.1
      */
-    public synchronized int getDefaultMaxPerRoute() {
+    public int getDefaultMaxPerRoute() {
         return this.defaultMax;
     }
 
-    public synchronized void setDefaultMaxPerRoute(int max) {
+    public void setDefaultMaxPerRoute(int max) {
         if (max < 1) {
             throw new IllegalArgumentException
                 ("The maximum must be greater than 0.");
@@ -84,7 +81,7 @@
         this.defaultMax = max;
     }
 
-    public synchronized void setMaxForRoute(final HttpRoute route, int max) {
+    public void setMaxForRoute(final HttpRoute route, int max) {
         if (route == null) {
             throw new IllegalArgumentException
                 ("HTTP route may not be null.");
@@ -96,7 +93,7 @@
         this.maxPerHostMap.put(route, Integer.valueOf(max));
     }
 
-    public synchronized int getMaxForRoute(final HttpRoute route) {
+    public int getMaxForRoute(final HttpRoute route) {
         if (route == null) {
             throw new IllegalArgumentException
                 ("HTTP route may not be null.");
@@ -109,7 +106,7 @@
         }
     }
     
-    public synchronized void setMaxForRoutes(final Map<HttpRoute, Integer> map) {
+    public void setMaxForRoutes(final Map<HttpRoute, Integer> map) {
         if (map == null) {
             return;
         }
@@ -118,7 +115,7 @@
     }
 
     @Override
-    public synchronized String toString() {
+    public String toString() {
         return this.maxPerHostMap.toString();
     }
     

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeRegistry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeRegistry.java?rev=897641&r1=897640&r2=897641&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeRegistry.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeRegistry.java
Sun Jan 10 14:23:56 2010
@@ -27,11 +27,10 @@
 package org.apache.http.conn.scheme;
 
 import java.util.ArrayList;
-import java.util.LinkedHashMap;
 import java.util.List;
 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.HttpHost;
@@ -46,15 +45,14 @@
 public final class SchemeRegistry {
 
     /** The available schemes in this registry. */
-    @GuardedBy("this")
-    private final Map<String,Scheme> registeredSchemes;
+    private final ConcurrentHashMap<String,Scheme> registeredSchemes;
 
     /**
      * Creates a new, empty scheme registry.
      */
     public SchemeRegistry() {
         super();
-        registeredSchemes = new LinkedHashMap<String,Scheme>();
+        registeredSchemes = new ConcurrentHashMap<String,Scheme>();
     }
 
     /**
@@ -67,7 +65,7 @@
      * @throws IllegalStateException
      *          if the scheme with the given name is not registered
      */
-    public synchronized final Scheme getScheme(String name) {
+    public final Scheme getScheme(String name) {
         Scheme found = get(name);
         if (found == null) {
             throw new IllegalStateException
@@ -87,7 +85,7 @@
      * @throws IllegalStateException
      *          if a scheme with the respective name is not registered
      */
-    public synchronized final Scheme getScheme(HttpHost host) {
+    public final Scheme getScheme(HttpHost host) {
         if (host == null) {
             throw new IllegalArgumentException("Host must not be null.");
         }
@@ -102,7 +100,7 @@
      * @return  the scheme, or
      *          <code>null</code> if there is none by this name
      */
-    public synchronized final Scheme get(String name) {
+    public final Scheme get(String name) {
         if (name == null)
             throw new IllegalArgumentException("Name must not be null.");
 
@@ -122,7 +120,7 @@
      * @return  the scheme previously registered with that name, or
      *          <code>null</code> if none was registered
      */
-    public synchronized final Scheme register(Scheme sch) {
+    public final Scheme register(Scheme sch) {
         if (sch == null)
             throw new IllegalArgumentException("Scheme must not be null.");
 
@@ -138,7 +136,7 @@
      * @return  the unregistered scheme, or
      *          <code>null</code> if there was none
      */
-    public synchronized final Scheme unregister(String name) {
+    public final Scheme unregister(String name) {
         if (name == null)
             throw new IllegalArgumentException("Name must not be null.");
 
@@ -149,11 +147,11 @@
     }
 
     /**
-     * Obtains the names of the registered schemes in their default order.
+     * Obtains the names of the registered schemes.
      *
      * @return  List containing registered scheme names.
      */
-    public synchronized final List<String> getSchemeNames() {
+    public final List<String> getSchemeNames() {
         return new ArrayList<String>(registeredSchemes.keySet());
     }
 
@@ -163,7 +161,7 @@
      * 
      * @param map protocol schemes
      */
-    public synchronized void setItems(final Map<String, Scheme> map) {
+    public void setItems(final Map<String, Scheme> map) {
         if (map == null) {
             return;
         }



Mime
View raw message