From 4753d7e3ac6dd7295a76dcfe7112260c10c01273 Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Fri, 20 Mar 2009 01:52:13 +0000 Subject: [PATCH] More ThreadSafe and Immutable classes git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@756296 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/http/impl/client/AbstractHttpClient.java | 3 +++ .../java/org/apache/http/impl/client/DefaultHttpClient.java | 3 +++ .../org/apache/http/impl/conn/DefaultHttpRoutePlanner.java | 5 ++++- .../org/apache/http/impl/conn/DefaultResponseParser.java | 3 +++ .../apache/http/impl/conn/LoggingSessionInputBuffer.java | 3 +++ .../apache/http/impl/conn/LoggingSessionOutputBuffer.java | 3 +++ .../apache/http/impl/conn/ProxySelectorRoutePlanner.java | 6 +++++- 7 files changed, 24 insertions(+), 2 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java index 51ef59212..fbffe7cfd 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java @@ -35,6 +35,8 @@ import java.io.IOException; import java.net.URI; import java.lang.reflect.UndeclaredThrowableException; +import net.jcip.annotations.ThreadSafe; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.ConnectionReuseStrategy; @@ -77,6 +79,7 @@ import org.apache.http.protocol.HttpRequestExecutor; * * @since 4.0 */ +@ThreadSafe public abstract class AbstractHttpClient implements HttpClient { private final Log log = LogFactory.getLog(getClass()); diff --git a/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java index e4006cd38..e0ea059e3 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java @@ -31,6 +31,8 @@ package org.apache.http.impl.client; +import net.jcip.annotations.ThreadSafe; + import org.apache.http.ConnectionReuseStrategy; import org.apache.http.HttpVersion; import org.apache.http.auth.AuthSchemeRegistry; @@ -96,6 +98,7 @@ import org.apache.http.util.VersionInfo; * * @since 4.0 */ +@ThreadSafe public class DefaultHttpClient extends AbstractHttpClient { diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java index 86a7d2cba..fab8b0fd1 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultHttpRoutePlanner.java @@ -34,6 +34,8 @@ package org.apache.http.impl.conn; import java.net.InetAddress; +import net.jcip.annotations.ThreadSafe; + import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; @@ -56,10 +58,11 @@ import org.apache.http.conn.params.ConnRouteParams; * * @since 4.0 */ +@ThreadSafe public class DefaultHttpRoutePlanner implements HttpRoutePlanner { /** The scheme registry. */ - protected SchemeRegistry schemeRegistry; + protected final SchemeRegistry schemeRegistry; // class is @ThreadSafe /** diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java index 4ac73cd84..d766b27d7 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/DefaultResponseParser.java @@ -33,6 +33,8 @@ package org.apache.http.impl.conn; import java.io.IOException; +import net.jcip.annotations.ThreadSafe; + import org.apache.http.HttpException; import org.apache.http.HttpMessage; import org.apache.http.HttpResponseFactory; @@ -51,6 +53,7 @@ import org.apache.http.util.CharArrayBuffer; * * @since 4.0 */ +@ThreadSafe // no public methods public class DefaultResponseParser extends AbstractMessageParser { private final HttpResponseFactory responseFactory; diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java b/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java index 80cecbec0..2ee1526af 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionInputBuffer.java @@ -32,6 +32,8 @@ package org.apache.http.impl.conn; import java.io.IOException; +import net.jcip.annotations.Immutable; + import org.apache.http.io.HttpTransportMetrics; import org.apache.http.io.SessionInputBuffer; import org.apache.http.util.CharArrayBuffer; @@ -42,6 +44,7 @@ import org.apache.http.util.CharArrayBuffer; * * @since 4.0 */ +@Immutable public class LoggingSessionInputBuffer implements SessionInputBuffer { /** Original session input buffer. */ diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java b/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java index d831d56fd..40647bbce 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/LoggingSessionOutputBuffer.java @@ -32,6 +32,8 @@ package org.apache.http.impl.conn; import java.io.IOException; +import net.jcip.annotations.Immutable; + import org.apache.http.io.HttpTransportMetrics; import org.apache.http.io.SessionOutputBuffer; import org.apache.http.util.CharArrayBuffer; @@ -42,6 +44,7 @@ import org.apache.http.util.CharArrayBuffer; * * @since 4.0 */ +@Immutable public class LoggingSessionOutputBuffer implements SessionOutputBuffer { /** Original data transmitter. */ diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java b/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java index 4e20dc88b..b3e09270f 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java @@ -40,6 +40,9 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.List; +import net.jcip.annotations.NotThreadSafe; +import net.jcip.annotations.ThreadSafe; + import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; @@ -65,10 +68,11 @@ import org.apache.http.conn.params.ConnRouteParams; * * @since 4.0 */ +@NotThreadSafe // e.g [gs]etProxySelector() public class ProxySelectorRoutePlanner implements HttpRoutePlanner { /** The scheme registry. */ - protected SchemeRegistry schemeRegistry; + protected final SchemeRegistry schemeRegistry; // @ThreadSafe /** The proxy selector to use, or null for system default. */ protected ProxySelector proxySelector;