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 2013/07/15 09:45:00 UTC

svn commit: r1503126 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client: HttpAsyncClientBuilder.java InternalHttpAsyncClient.java

Author: olegk
Date: Mon Jul 15 07:45:00 2013
New Revision: 1503126

URL: http://svn.apache.org/r1503126
Log:
HTTPASYNC-48: InternalHttpAsyncClientThread.reactorThread should be created via ThreadFactory
Contributed by Dmitry Potapov <po...@gmail.com>

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java?rev=1503126&r1=1503125&r2=1503126&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java Mon Jul 15 07:45:00 2013
@@ -30,6 +30,8 @@ package org.apache.http.impl.nio.client;
 import java.net.ProxySelector;
 import java.util.Collection;
 import java.util.LinkedList;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
 
 import javax.net.ssl.SSLContext;
 
@@ -133,6 +135,8 @@ public class HttpAsyncClientBuilder {
     private ConnectionConfig defaultConnectionConfig;
     private RequestConfig defaultRequestConfig;
 
+    private ThreadFactory threadFactory;
+
     private boolean systemProperties;
     private boolean cookieManagementDisabled;
     private boolean authCachingDisabled;
@@ -323,6 +327,11 @@ public class HttpAsyncClientBuilder {
         return this;
     }
 
+    public final HttpAsyncClientBuilder setThreadFactory(final ThreadFactory threadFactory) {
+        this.threadFactory = threadFactory;
+        return this;
+    }
+
     public final HttpAsyncClientBuilder disableConnectionState() {
         connectionStateDisabled = true;
         return this;
@@ -528,6 +537,16 @@ public class HttpAsyncClientBuilder {
             redirectStrategy = DefaultRedirectStrategy.INSTANCE;
         }
 
+        RequestConfig defaultRequestConfig = this.defaultRequestConfig;
+        if (defaultRequestConfig == null) {
+            defaultRequestConfig = RequestConfig.DEFAULT;
+        }
+
+        ThreadFactory threadFactory = this.threadFactory;
+        if (threadFactory == null) {
+            threadFactory = Executors.defaultThreadFactory();
+        }
+
         final MainClientExec exec = new MainClientExec(
             connManager,
             httpprocessor,
@@ -546,7 +565,8 @@ public class HttpAsyncClientBuilder {
             authSchemeRegistry,
             defaultCookieStore,
             defaultCredentialsProvider,
-            defaultRequestConfig != null ? defaultRequestConfig : RequestConfig.DEFAULT);
+            defaultRequestConfig,
+            threadFactory);
     }
 
 }

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java?rev=1503126&r1=1503125&r2=1503126&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java Mon Jul 15 07:45:00 2013
@@ -28,6 +28,7 @@ package org.apache.http.impl.nio.client;
 
 import java.io.IOException;
 import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -75,7 +76,8 @@ class InternalHttpAsyncClient extends Cl
             final Lookup<AuthSchemeProvider> authSchemeRegistry,
             final CookieStore cookieStore,
             final CredentialsProvider credentialsProvider,
-            final RequestConfig defaultConfig) {
+            final RequestConfig defaultConfig,
+            final ThreadFactory threadFactory) {
         super();
         this.connmgr = connmgr;
         this.exec = exec;
@@ -84,14 +86,14 @@ class InternalHttpAsyncClient extends Cl
         this.cookieStore = cookieStore;
         this.credentialsProvider = credentialsProvider;
         this.defaultConfig = defaultConfig;
-        this.reactorThread = new Thread() {
+        this.reactorThread = threadFactory.newThread(new Runnable() {
 
             @Override
             public void run() {
                 doExecute();
             }
 
-        };
+        });
         this.status = IOReactorStatus.INACTIVE;
     }