jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1643541 - /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
Date Sat, 06 Dec 2014 15:20:31 GMT
On 6 December 2014 at 15:13,  <pmouawad@apache.org> wrote:
> Author: pmouawad
> Date: Sat Dec  6 15:12:59 2014
> New Revision: 1643541
>
> URL: http://svn.apache.org/r1643541
> Log:
> Remove useless import
> Rename map and HTTPCLIENTS to make code clearer

-0

The new field name is very long.
I would question if it makes the code easier to read.

I think I would have just added the Javadoc - this should be
sufficient in most IDEs as it will pop up when hovering over the name.

So long as the name is not actually misleading or easily confused with
another, I'm not sure its worth renaming.

> Modified:
>     jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
>
> Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1643541&r1=1643540&r2=1643541&view=diff
> ==============================================================================
> --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
(original)
> +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
Sat Dec  6 15:12:59 2014
> @@ -108,7 +108,6 @@ import org.apache.jmeter.protocol.http.c
>  import org.apache.jmeter.protocol.http.control.CacheManager;
>  import org.apache.jmeter.protocol.http.control.CookieManager;
>  import org.apache.jmeter.protocol.http.control.HeaderManager;
> -import org.apache.jmeter.protocol.http.sampler.HttpWebdav;
>  import org.apache.jmeter.protocol.http.util.EncoderCache;
>  import org.apache.jmeter.protocol.http.util.HC4TrustAllSSLSocketFactory;
>  import org.apache.jmeter.protocol.http.util.HTTPArgument;
> @@ -179,7 +178,10 @@ public class HTTPHC4Impl extends HTTPHCA
>          }
>      };
>
> -    private static final ThreadLocal<Map<HttpClientKey, HttpClient>> HTTPCLIENTS
=
> +    /**
> +     * 1 HttpClient instance per combination of (HttpClient,HttpClientKey)
> +     */
> +    private static final ThreadLocal<Map<HttpClientKey, HttpClient>> HTTPCLIENTS_CACHE_PER_THREAD_AND_HTTPCLIENTKEY
=
>          new ThreadLocal<Map<HttpClientKey, HttpClient>>(){
>          @Override
>          protected Map<HttpClientKey, HttpClient> initialValue() {
> @@ -277,7 +279,7 @@ public class HTTPHC4Impl extends HTTPHCA
>          HTTPSampleResult res = createSampleResult(url, method);
>
>          HttpClient httpClient = setupClient(url);
> -
> +
>          HttpRequestBase httpRequest = null;
>          try {
>              URI uri = url.toURI();
> @@ -607,7 +609,7 @@ public class HTTPHC4Impl extends HTTPHCA
>
>      private HttpClient setupClient(URL url) {
>
> -        Map<HttpClientKey, HttpClient> map = HTTPCLIENTS.get();
> +        Map<HttpClientKey, HttpClient> mapHttpClientPerHttpClientKey = HTTPCLIENTS_CACHE_PER_THREAD_AND_HTTPCLIENTKEY.get();
>
>          final String host = url.getHost();
>          final String proxyHost = getProxyHost();
> @@ -623,7 +625,7 @@ public class HTTPHC4Impl extends HTTPHCA
>                  useDynamicProxy ? getProxyUser() : PROXY_USER,
>                  useDynamicProxy ? getProxyPass() : PROXY_PASS);
>
> -        HttpClient httpClient = map.get(key);
> +        HttpClient httpClient = mapHttpClientPerHttpClientKey.get(key);
>
>          if (httpClient != null && resetSSLContext && HTTPConstants.PROTOCOL_HTTPS.equalsIgnoreCase(url.getProtocol()))
{
>              ((AbstractHttpClient) httpClient).clearRequestInterceptors();
> @@ -698,7 +700,7 @@ public class HTTPHC4Impl extends HTTPHCA
>                  log.debug("Created new HttpClient: @"+System.identityHashCode(httpClient)
+ " " + key.toString());
>              }
>
> -            map.put(key, httpClient); // save the agent for next time round
> +            mapHttpClientPerHttpClientKey.put(key, httpClient); // save the agent for
next time round
>          } else {
>              if (log.isDebugEnabled()) {
>                  log.debug("Reusing the HttpClient: @"+System.identityHashCode(httpClient)
+ " " + key.toString());
> @@ -1306,14 +1308,14 @@ public class HTTPHC4Impl extends HTTPHCA
>       */
>      private void closeThreadLocalConnections() {
>          // Does not need to be synchronised, as all access is from same thread
> -        Map<HttpClientKey, HttpClient> map = HTTPCLIENTS.get();
> -        if ( map != null ) {
> -            for ( HttpClient cl : map.values() ) {
> +        Map<HttpClientKey, HttpClient> mapHttpClientPerHttpClientKey = HTTPCLIENTS_CACHE_PER_THREAD_AND_HTTPCLIENTKEY.get();
> +        if ( mapHttpClientPerHttpClientKey != null ) {
> +            for ( HttpClient cl : mapHttpClientPerHttpClientKey.values() ) {
>                  ((AbstractHttpClient) cl).clearRequestInterceptors();
>                  ((AbstractHttpClient) cl).clearResponseInterceptors();
>                  cl.getConnectionManager().shutdown();
>              }
> -            map.clear();
> +            mapHttpClientPerHttpClientKey.clear();
>          }
>      }
>
>
>

Mime
View raw message