tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1164607 - /tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
Date Fri, 02 Sep 2011 16:17:53 GMT
Author: rfeng
Date: Fri Sep  2 16:17:53 2011
New Revision: 1164607

URL: http://svn.apache.org/viewvc?rev=1164607&view=rev
Log:
Turn the http client factory into a utility

Modified:
    tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java

Modified: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java?rev=1164607&r1=1164606&r2=1164607&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
Fri Sep  2 16:17:53 2011
@@ -23,6 +23,8 @@ import org.apache.http.HttpHost;
 import org.apache.http.client.HttpClient;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.params.ConnManagerParams;
+import org.apache.http.conn.params.ConnPerRoute;
+import org.apache.http.conn.params.ConnPerRouteBean;
 import org.apache.http.conn.scheme.PlainSocketFactory;
 import org.apache.http.conn.scheme.Scheme;
 import org.apache.http.conn.scheme.SchemeRegistry;
@@ -34,18 +36,29 @@ import org.apache.http.params.HttpConnec
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HTTP;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.LifeCycleListener;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
 
 /**
  * @version $Rev$ $Date$
  */
-public class HttpClientFactory {
+public class HttpClientFactory implements LifeCycleListener {
+
+    private HttpClient httpClient;
+
+    public static HttpClientFactory getInstance(ExtensionPointRegistry registry) {
+        UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+        return utilities.getUtility(HttpClientFactory.class);
+    }
 
     public HttpClient createHttpClient() {
         HttpParams defaultParameters = new BasicHttpParams();
         //defaultParameters.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS,
10);
 
-        ConnManagerParams.setMaxTotalConnections(defaultParameters, 160);
-        // ConnManagerParams.setMaxConnectionsPerRoute(defaultParameters, ConnPerRoute);
+        ConnManagerParams.setMaxTotalConnections(defaultParameters, 1024);
+        ConnPerRoute connPerRoute = new ConnPerRouteBean(256);
+        ConnManagerParams.setMaxConnectionsPerRoute(defaultParameters, connPerRoute);
 
         HttpProtocolParams.setContentCharset(defaultParameters, HTTP.UTF_8);
         HttpConnectionParams.setConnectionTimeout(defaultParameters, 60000);
@@ -58,8 +71,25 @@ public class HttpClientFactory {
         ClientConnectionManager connectionManager =
             new ThreadSafeClientConnManager(defaultParameters, supportedSchemes);
 
+        return new DefaultHttpClient(connectionManager, defaultParameters);
+    }
 
+    @Override
+    public void start() {
+        if (httpClient == null) {
+            httpClient = createHttpClient();
+        }
+    }
 
-        return new DefaultHttpClient(connectionManager, defaultParameters);
+    @Override
+    public void stop() {
+        if (httpClient != null) {
+            httpClient.getConnectionManager().shutdown();
+            httpClient = null;
+        }
+    }
+
+    public HttpClient getHttpClient() {
+        return httpClient;
     }
 }



Mime
View raw message