hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1586763 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src: main/java/org/apache/http/impl/nio/client/ test/java/org/apache/http/localserver/
Date Fri, 11 Apr 2014 19:54:25 GMT
Author: olegk
Date: Fri Apr 11 19:54:25 2014
New Revision: 1586763

URL: http://svn.apache.org/r1586763
Log:
HTTPASYNC-75: added setter for NHttpClientEventHandler to HttpAsyncClientBuilder
Contributed by Dmitry Potapov <potapov.d at gmail.com>

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java
    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
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/RandomHandler.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java?rev=1586763&r1=1586762&r2=1586763&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/CloseableHttpAsyncClientBase.java
Fri Apr 11 19:54:25 2014
@@ -28,6 +28,7 @@ package org.apache.http.impl.nio.client;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.http.nio.NHttpClientEventHandler;
 import org.apache.http.nio.conn.NHttpClientConnectionManager;
 import org.apache.http.nio.reactor.IOEventDispatch;
 
@@ -48,22 +49,23 @@ abstract class CloseableHttpAsyncClientB
 
     public CloseableHttpAsyncClientBase(
             final NHttpClientConnectionManager connmgr,
-            final ThreadFactory threadFactory) {
+            final ThreadFactory threadFactory,
+            final NHttpClientEventHandler handler) {
         super();
         this.connmgr = connmgr;
         this.reactorThread = threadFactory.newThread(new Runnable() {
 
             public void run() {
-                doExecute();
+                doExecute(handler);
             }
 
         });
         this.status = new AtomicReference<Status>(Status.INACTIVE);
     }
 
-    private void doExecute() {
+    private void doExecute(final NHttpClientEventHandler handler) {
         try {
-            final IOEventDispatch ioEventDispatch = new InternalIODispatch();
+            final IOEventDispatch ioEventDispatch = new InternalIODispatch(handler);
             this.connmgr.execute(ioEventDispatch);
         } catch (final Exception ex) {
             this.log.error("I/O reactor terminated abnormally", ex);

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=1586763&r1=1586762&r2=1586763&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
Fri Apr 11 19:54:25 2014
@@ -92,6 +92,7 @@ import org.apache.http.impl.cookie.RFC21
 import org.apache.http.impl.cookie.RFC2965SpecFactory;
 import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
 import org.apache.http.impl.nio.reactor.IOReactorConfig;
+import org.apache.http.nio.NHttpClientEventHandler;
 import org.apache.http.nio.conn.NHttpClientConnectionManager;
 import org.apache.http.nio.conn.NoopIOSessionStrategy;
 import org.apache.http.nio.conn.SchemeIOSessionStrategy;
@@ -181,6 +182,7 @@ public class HttpAsyncClientBuilder {
     private RequestConfig defaultRequestConfig;
 
     private ThreadFactory threadFactory;
+    private NHttpClientEventHandler eventHandler;
 
     private boolean systemProperties;
     private boolean cookieManagementDisabled;
@@ -531,6 +533,16 @@ public class HttpAsyncClientBuilder {
     }
 
     /**
+     * Assigns {@link NHttpClientEventHandler} instance.
+     *
+     * @since 4.1
+     */
+    public final HttpAsyncClientBuilder setEventHandler(final NHttpClientEventHandler eventHandler)
{
+        this.eventHandler = eventHandler;
+        return this;
+    }
+
+    /**
      * Disables connection state tracking.
      */
     public final HttpAsyncClientBuilder disableConnectionState() {
@@ -779,6 +791,11 @@ public class HttpAsyncClientBuilder {
             threadFactory = Executors.defaultThreadFactory();
         }
 
+        NHttpClientEventHandler eventHandler = this.eventHandler;
+        if (eventHandler == null) {
+            eventHandler = new LoggingAsyncRequestExecutor();
+        }
+
         final MainClientExec exec = new MainClientExec(
             connManager,
             httpprocessor,
@@ -798,7 +815,8 @@ public class HttpAsyncClientBuilder {
             defaultCookieStore,
             defaultCredentialsProvider,
             defaultRequestConfig,
-            threadFactory);
+            threadFactory,
+            eventHandler);
     }
 
 }

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=1586763&r1=1586762&r2=1586763&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
Fri Apr 11 19:54:25 2014
@@ -41,6 +41,7 @@ import org.apache.http.concurrent.BasicF
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.config.Lookup;
 import org.apache.http.cookie.CookieSpecProvider;
+import org.apache.http.nio.NHttpClientEventHandler;
 import org.apache.http.nio.conn.NHttpClientConnectionManager;
 import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
 import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
@@ -68,8 +69,9 @@ class InternalHttpAsyncClient extends Cl
             final CookieStore cookieStore,
             final CredentialsProvider credentialsProvider,
             final RequestConfig defaultConfig,
-            final ThreadFactory threadFactory) {
-        super(connmgr, threadFactory);
+            final ThreadFactory threadFactory,
+            final NHttpClientEventHandler eventHandler) {
+        super(connmgr, threadFactory, eventHandler);
         this.connmgr = connmgr;
         this.exec = exec;
         this.cookieSpecRegistry = cookieSpecRegistry;

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java?rev=1586763&r1=1586762&r2=1586763&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
Fri Apr 11 19:54:25 2014
@@ -38,9 +38,9 @@ class InternalIODispatch extends Abstrac
 
     private final NHttpClientEventHandler handler;
 
-    public InternalIODispatch() {
+    public InternalIODispatch(final NHttpClientEventHandler handler) {
         super();
-        this.handler = new LoggingAsyncRequestExecutor();
+        this.handler = handler;
     }
 
     @Override

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java?rev=1586763&r1=1586762&r2=1586763&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
Fri Apr 11 19:54:25 2014
@@ -38,6 +38,7 @@ import org.apache.http.concurrent.BasicF
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
+import org.apache.http.nio.NHttpClientEventHandler;
 import org.apache.http.nio.conn.NHttpClientConnectionManager;
 import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
 import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
@@ -60,8 +61,9 @@ class MinimalHttpAsyncClient extends Clo
 
     public MinimalHttpAsyncClient(
             final NHttpClientConnectionManager connmgr,
-            final ThreadFactory threadFactory) {
-        super(connmgr, threadFactory);
+            final ThreadFactory threadFactory,
+            final NHttpClientEventHandler eventHandler) {
+        super(connmgr, threadFactory, eventHandler);
         this.connmgr = connmgr;
         final HttpProcessor httpProcessor = new ImmutableHttpProcessor(new RequestContent(),
                 new RequestTargetHost(),
@@ -76,6 +78,12 @@ class MinimalHttpAsyncClient extends Clo
     }
 
     public MinimalHttpAsyncClient(
+            final NHttpClientConnectionManager connmgr,
+            final ThreadFactory threadFactory) {
+        this(connmgr, threadFactory, new LoggingAsyncRequestExecutor());
+    }
+
+    public MinimalHttpAsyncClient(
             final NHttpClientConnectionManager connmgr) {
         this(connmgr, Executors.defaultThreadFactory());
     }

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/RandomHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/RandomHandler.java?rev=1586763&r1=1586762&r2=1586763&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/RandomHandler.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/RandomHandler.java
Fri Apr 11 19:54:25 2014
@@ -28,7 +28,6 @@
 package org.apache.http.localserver;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.util.Locale;
 
 import org.apache.http.Consts;



Mime
View raw message