You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/09/26 23:32:32 UTC

svn commit: r1390740 - in /cxf/trunk/rt/transports/http-hc/src: main/java/org/apache/cxf/transport/http/asyncclient/ main/resources/OSGI-INF/blueprint/ main/resources/OSGI-INF/metatype/ test/java/org/apache/cxf/transport/http/asyncclient/

Author: dkulp
Date: Wed Sep 26 21:32:31 2012
New Revision: 1390740

URL: http://svn.apache.org/viewvc?rev=1390740&view=rev
Log:
Add a connection TTL for the async connections.  Full Keep-Alive timeouts is broken in Apache AsyncClient, patch submitted.

Modified:
    cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
    cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java
    cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/blueprint/cxf-http-async.xml
    cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/metatype/cxf-http-async.xml
    cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java

Modified: cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java?rev=1390740&r1=1390739&r2=1390740&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java Wed Sep 26 21:32:31 2012
@@ -61,6 +61,7 @@ import org.apache.cxf.message.MessageUti
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.http.Headers;
 import org.apache.cxf.transport.http.URLConnectionHTTPConduit;
+import org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduitFactory.UseAsyncPolicy;
 import org.apache.cxf.transport.https.AliasedX509ExtendedKeyManager;
 import org.apache.cxf.transport.https.CertificateHostnameVerifier;
 import org.apache.cxf.transport.https.HttpsURLConnectionInfo;
@@ -115,7 +116,10 @@ public class AsyncHTTPConduit extends UR
         
         Object o = message.getContextualProperty(USE_ASYNC);
         if (o == null) {
-            switch (factory.getUseAsyncPolicy()) {
+            o = factory.getUseAsyncPolicy();
+        }
+        if (o instanceof UseAsyncPolicy) {
+            switch ((UseAsyncPolicy)o) {
             case ALWAYS:
                 o = true;
                 break;

Modified: cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java?rev=1390740&r1=1390739&r2=1390740&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java (original)
+++ cxf/trunk/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitFactory.java Wed Sep 26 21:32:31 2012
@@ -22,6 +22,7 @@ package org.apache.cxf.transport.http.as
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import javax.annotation.Resource;
 
@@ -76,6 +77,7 @@ public class AsyncHTTPConduitFactory imp
     public static final String MAX_CONNECTIONS = "org.apache.cxf.transport.http.async.MAX_CONNECTIONS";
     public static final String MAX_PER_HOST_CONNECTIONS 
         = "org.apache.cxf.transport.http.async.MAX_PER_HOST_CONNECTIONS";
+    public static final String CONNECTION_TTL = "org.apache.cxf.transport.http.async.CONNECTION_TTL";
     
     //AsycClient specific props
     public static final String THREAD_COUNT = "org.apache.cxf.transport.http.async.ioThreadCount";
@@ -99,6 +101,7 @@ public class AsyncHTTPConduitFactory imp
     UseAsyncPolicy policy;
     int maxConnections = 5000;
     int maxPerRoute = 1000;
+    int connectionTTL = 60000;
     
     
     public AsyncHTTPConduitFactory(Map<String, Object> conf) {
@@ -152,6 +155,7 @@ public class AsyncHTTPConduitFactory imp
         }
         
         maxConnections = getInt(s.get(MAX_CONNECTIONS), maxConnections);
+        connectionTTL = getInt(s.get(CONNECTION_TTL), connectionTTL);
         maxPerRoute = getInt(s.get(MAX_PER_HOST_CONNECTIONS), maxPerRoute);
         if (connectionManager != null) {
             connectionManager.setMaxTotal(maxConnections);
@@ -301,7 +305,8 @@ public class AsyncHTTPConduitFactory imp
         registry.register(new AsyncScheme("http", 80, null));
         registry.register(new AsyncScheme("https", 443, null));
 
-        connectionManager = new PoolingClientAsyncConnectionManager(ioReactor, registry) {
+        connectionManager = new PoolingClientAsyncConnectionManager(ioReactor, registry, 
+                                                                    connectionTTL, TimeUnit.MILLISECONDS) {
             @Override
             protected ClientAsyncConnectionFactory createClientAsyncConnectionFactory() {
                 final HttpResponseFactory responseFactory = new DefaultHttpResponseFactory();

Modified: cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/blueprint/cxf-http-async.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/blueprint/cxf-http-async.xml?rev=1390740&r1=1390739&r2=1390740&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/blueprint/cxf-http-async.xml (original)
+++ cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/blueprint/cxf-http-async.xml Wed Sep 26 21:32:31 2012
@@ -39,6 +39,7 @@ under the License.
       <cm:property name="org.apache.cxf.transport.http.async.usePolicy" value="ASYNC_ONLY"/>
       
       <cm:property name="org.apache.cxf.transport.http.async.MAX_CONNECTIONS" value="5000"/>
+      <cm:property name="org.apache.cxf.transport.http.async.CONNECTION_TTL" value="60000"/>
       <cm:property name="org.apache.cxf.transport.http.async.MAX_PER_HOST_CONNECTIONS" value="1000"/>
     </cm:default-properties>
   </cm:property-placeholder>
@@ -58,6 +59,7 @@ under the License.
             <entry key="org.apache.cxf.transport.http.async.SO_TIMEOUT" value="${org.apache.cxf.transport.http.async.SO_TIMEOUT}"/>
 
             <entry key="org.apache.cxf.transport.http.async.usePolicy" value="${org.apache.cxf.transport.http.async.usePolicy}"/>
+            <entry key="org.apache.cxf.transport.http.async.CONNECTION_TTL" value="${org.apache.cxf.transport.http.async.CONNECTION_TTL}"/>
             <entry key="org.apache.cxf.transport.http.async.MAX_CONNECTIONS" value="${org.apache.cxf.transport.http.async.MAX_CONNECTIONS}"/>
             <entry key="org.apache.cxf.transport.http.async.MAX_PER_HOST_CONNECTIONS" value="${org.apache.cxf.transport.http.async.MAX_PER_HOST_CONNECTIONS}"/>
         </map>

Modified: cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/metatype/cxf-http-async.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/metatype/cxf-http-async.xml?rev=1390740&r1=1390739&r2=1390740&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/metatype/cxf-http-async.xml (original)
+++ cxf/trunk/rt/transports/http-hc/src/main/resources/OSGI-INF/metatype/cxf-http-async.xml Wed Sep 26 21:32:31 2012
@@ -62,6 +62,11 @@ under the License.
             type="String" 
             default="ASYNC_ONLY" 
             description="" /> 
+        <AD name="CONNECTION_TTL" 
+            id="org.apache.cxf.transport.http.async.CONNECTION_TTL"
+            type="Integer" 
+            default="60000" 
+            description="" /> 
         <AD name="MAX_CONNECTIONS" 
             id="org.apache.cxf.transport.http.async.MAX_CONNECTIONS"
             type="Integer" 

Modified: cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java?rev=1390740&r1=1390739&r2=1390740&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java (original)
+++ cxf/trunk/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java Wed Sep 26 21:32:31 2012
@@ -29,6 +29,7 @@ import javax.xml.ws.Endpoint;
 import javax.xml.ws.Response;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.continuations.Continuation;
 import org.apache.cxf.continuations.ContinuationProvider;
 import org.apache.cxf.frontend.ClientProxy;
@@ -57,7 +58,8 @@ public class AsyncHTTPConduitTest extend
     @BeforeClass
     public static void start() throws Exception {
         Bus b = createStaticBus();
-        new AsyncHTTPConduitFactory(b);
+        b.setProperty(AsyncHTTPConduit.USE_ASYNC, AsyncHTTPConduitFactory.UseAsyncPolicy.ALWAYS);
+        BusFactory.setThreadDefaultBus(b);
         ep = Endpoint.publish("http://localhost:" + PORT + "/SoapContext/SoapPort",
                               new org.apache.hello_world_soap_http.GreeterImpl() {
                 public String greetMeLater(long cnt) {