You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2010/02/27 12:56:15 UTC

svn commit: r916944 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/protocol/ test/java/org/apache/http/mockup/

Author: olegk
Date: Sat Feb 27 11:56:15 2010
New Revision: 916944

URL: http://svn.apache.org/viewvc?rev=916944&view=rev
Log:
* Made methods of UriPatternMatcher synchronized
* Deprecated all setter methods in HttpService

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpService.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java?rev=916944&r1=916943&r2=916944&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java Sat Feb 27 11:56:15 2010
@@ -85,7 +85,7 @@
      * @param map the map containing handlers keyed by their URI patterns.
      */
     public void setHandlers(final Map map) {
-        matcher.setHandlers(map);
+        matcher.setObjects(map);
     }
 
     public HttpRequestHandler lookup(final String requestURI) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpService.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpService.java?rev=916944&r1=916943&r2=916944&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpService.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpService.java Sat Feb 27 11:56:15 2010
@@ -69,19 +69,85 @@
  */
 public class HttpService {
 
-    private HttpParams params = null;
-    private HttpProcessor processor = null;
-    private HttpRequestHandlerResolver handlerResolver = null;
-    private ConnectionReuseStrategy connStrategy = null;
-    private HttpResponseFactory responseFactory = null;
-    private HttpExpectationVerifier expectationVerifier = null;
+    /**
+     * TODO: make all variables final in the next major version
+     */
+    private volatile HttpParams params = null;
+    private volatile HttpProcessor processor = null;
+    private volatile HttpRequestHandlerResolver handlerResolver = null;
+    private volatile ConnectionReuseStrategy connStrategy = null;
+    private volatile HttpResponseFactory responseFactory = null;
+    private volatile HttpExpectationVerifier expectationVerifier = null;
+
+    /**
+     * Create a new HTTP service.
+     *
+     * @param processor            the processor to use on requests and responses
+     * @param connStrategy         the connection reuse strategy
+     * @param responseFactory      the response factory
+     * @param handlerResolver      the handler resolver. May be null.
+     * @param expectationVerifier  the expectation verifier. May be null.
+     * @param params               the HTTP parameters
+     * 
+     * @since 4.1
+     */
+    public HttpService(
+            final HttpProcessor processor,
+            final ConnectionReuseStrategy connStrategy,
+            final HttpResponseFactory responseFactory,
+            final HttpRequestHandlerResolver handlerResolver,
+            final HttpExpectationVerifier expectationVerifier,
+            final HttpParams params) {
+        super();
+        if (processor == null) {
+            throw new IllegalArgumentException("HTTP processor may not be null");
+        }
+        if (connStrategy == null) {
+            throw new IllegalArgumentException("Connection reuse strategy may not be null");
+        }
+        if (responseFactory == null) {
+            throw new IllegalArgumentException("Response factory may not be null");
+        }
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        this.processor = processor;
+        this.connStrategy = connStrategy;
+        this.responseFactory = responseFactory;
+        this.handlerResolver = handlerResolver;
+        this.expectationVerifier = expectationVerifier;
+        this.params = params;
+    }
     
     /**
      * Create a new HTTP service.
      *
+     * @param processor            the processor to use on requests and responses
+     * @param connStrategy         the connection reuse strategy
+     * @param responseFactory      the response factory
+     * @param handlerResolver      the handler resolver. May be null.
+     * @param params               the HTTP parameters
+     * 
+     * @since 4.1
+     */
+    public HttpService(
+            final HttpProcessor processor,
+            final ConnectionReuseStrategy connStrategy,
+            final HttpResponseFactory responseFactory,
+            final HttpRequestHandlerResolver handlerResolver,
+            final HttpParams params) {
+        this(processor, connStrategy, responseFactory, handlerResolver, null, params);
+    }
+
+    /**
+     * Create a new HTTP service.
+     *
      * @param proc             the processor to use on requests and responses
      * @param connStrategy     the connection reuse strategy
      * @param responseFactory  the response factory
+     * 
+     * @deprecated use {@link HttpService#HttpService(HttpProcessor, 
+     *  ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerResolver, HttpParams)}
      */
     public HttpService(
             final HttpProcessor proc,
@@ -93,6 +159,9 @@
         setResponseFactory(responseFactory);
     }
     
+    /**
+     * @deprecated set {@link HttpProcessor} using constructor
+     */
     public void setHttpProcessor(final HttpProcessor processor) {
         if (processor == null) {
             throw new IllegalArgumentException("HTTP processor may not be null");
@@ -100,6 +169,9 @@
         this.processor = processor;
     }
 
+    /**
+     * @deprecated set {@link ConnectionReuseStrategy} using constructor
+     */
     public void setConnReuseStrategy(final ConnectionReuseStrategy connStrategy) {
         if (connStrategy == null) {
             throw new IllegalArgumentException("Connection reuse strategy may not be null");
@@ -107,6 +179,9 @@
         this.connStrategy = connStrategy;
     }
 
+    /**
+     * @deprecated set {@link HttpResponseFactory} using constructor
+     */
     public void setResponseFactory(final HttpResponseFactory responseFactory) {
         if (responseFactory == null) {
             throw new IllegalArgumentException("Response factory may not be null");
@@ -114,10 +189,23 @@
         this.responseFactory = responseFactory;
     }
     
+    /**
+     * @deprecated set {@link HttpResponseFactory} using constructor
+     */
+    public void setParams(final HttpParams params) {
+        this.params = params;
+    }
+    
+    /**
+     * @deprecated set {@link HttpRequestHandlerResolver} using constructor
+     */
     public void setHandlerResolver(final HttpRequestHandlerResolver handlerResolver) {
         this.handlerResolver = handlerResolver;
     }
 
+    /**
+     * @deprecated set {@link HttpExpectationVerifier} using constructor
+     */
     public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier) {
         this.expectationVerifier = expectationVerifier;
     }
@@ -126,10 +214,6 @@
         return this.params;
     }
     
-    public void setParams(final HttpParams params) {
-        this.params = params;
-    }
-    
     /**
      * Handles receives one HTTP request over the given connection within the 
      * given execution context and sends a response back to the client.

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java?rev=916944&r1=916943&r2=916944&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/UriPatternMatcher.java Sat Feb 27 11:56:15 2010
@@ -48,6 +48,9 @@
  */
 public class UriPatternMatcher {
 
+    /**
+     * TODO: Replace with ConcurrentHashMap
+     */
     private final Map map;
 
     public UriPatternMatcher() {
@@ -61,7 +64,7 @@
      * @param pattern the pattern to register the handler for.
      * @param obj the object.
      */
-    public void register(final String pattern, final Object obj) {
+    public synchronized void register(final String pattern, final Object obj) {
         if (pattern == null) {
             throw new IllegalArgumentException("URI request pattern may not be null");
         }
@@ -73,7 +76,7 @@
      *  
      * @param pattern the pattern to unregister.
      */
-    public void unregister(final String pattern) {
+    public synchronized void unregister(final String pattern) {
         if (pattern == null) {
             return;
         }
@@ -81,12 +84,21 @@
     }
 
     /**
+     * @deprecated use {@link #setObjects(Map)}
+     */
+    public synchronized void setHandlers(final Map map) {
+        if (map == null) {
+            throw new IllegalArgumentException("Map of handlers may not be null");
+        }
+        this.map.clear();
+        this.map.putAll(map);
+    }
+
+    /**
      * Sets objects from the given map.
      * @param map the map containing objects keyed by their URI patterns.
-     * <br>
-     * TODO: deprecate and rename to setObjects()
      */
-    public void setHandlers(final Map map) {
+    public synchronized void setObjects(final Map map) {
         if (map == null) {
             throw new IllegalArgumentException("Map of handlers may not be null");
         }
@@ -100,7 +112,7 @@
      * @param requestURI the request URI
      * @return object or <code>null</code> if no match is found.
      */
-    public Object lookup(String requestURI) {
+    public synchronized Object lookup(String requestURI) {
         if (requestURI == null) {
             throw new IllegalArgumentException("Request URI may not be null");
         }
@@ -111,8 +123,8 @@
         }
 
         // direct match?
-        Object handler = this.map.get(requestURI);
-        if (handler == null) {
+        Object obj = this.map.get(requestURI);
+        if (obj == null) {
             // pattern match?
             String bestMatch = null;
             for (Iterator it = this.map.keySet().iterator(); it.hasNext();) {
@@ -122,13 +134,13 @@
                     if (bestMatch == null
                             || (bestMatch.length() < pattern.length())
                             || (bestMatch.length() == pattern.length() && pattern.endsWith("*"))) {
-                        handler = this.map.get(pattern);
+                        obj = this.map.get(pattern);
                         bestMatch = pattern;
                     }
                 }
             }
         }
-        return handler;
+        return obj;
     }
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java?rev=916944&r1=916943&r2=916944&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java Sat Feb 27 11:56:15 2010
@@ -135,11 +135,10 @@
                         HttpService httpService = new HttpService(
                                 httpproc, 
                                 connStrategy,
-                                responseFactory);
-                        httpService.setParams(params);
-                        httpService.setExpectationVerifier(expectationVerifier);
-                        httpService.setHandlerResolver(reqistry);
-                        
+                                responseFactory,
+                                reqistry,
+                                expectationVerifier,
+                                params);
                         // Start worker thread
                         Thread t = new WorkerThread(httpService, conn);
                         t.setDaemon(true);