servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lh...@apache.org
Subject svn commit: r1133867 - in /servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http: HttpComponent.java HttpConfiguration.java endpoints/HttpProviderEndpoint.java
Date Thu, 09 Jun 2011 13:31:16 GMT
Author: lhein
Date: Thu Jun  9 13:31:15 2011
New Revision: 1133867

URL: http://svn.apache.org/viewvc?rev=1133867&view=rev
Log:
applied patch to set client timeouts and max connections (see ESB-1328)

Modified:
    servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
    servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
    servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java

Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java?rev=1133867&r1=1133866&r2=1133867&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
(original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpComponent.java
Thu Jun  9 13:31:15 2011
@@ -16,26 +16,12 @@
  */
 package org.apache.servicemix.http;
 
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.servicedesc.ServiceEndpoint;
-
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
 import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
-import org.apache.servicemix.common.BaseServiceUnitManager;
-import org.apache.servicemix.common.DefaultComponent;
-import org.apache.servicemix.common.Deployer;
-import org.apache.servicemix.common.Endpoint;
-import org.apache.servicemix.common.ServiceUnit;
-import org.apache.servicemix.common.DefaultServiceUnit;
+import org.apache.servicemix.common.*;
 import org.apache.servicemix.common.util.IntrospectionSupport;
 import org.apache.servicemix.common.util.URISupport;
-import org.apache.servicemix.common.security.AuthenticationService;
-import org.apache.servicemix.common.security.KeystoreManager;
 import org.apache.servicemix.common.xbean.BaseXBeanDeployer;
 import org.apache.servicemix.http.endpoints.HttpConsumerEndpoint;
 import org.apache.servicemix.http.endpoints.HttpProviderEndpoint;
@@ -43,6 +29,12 @@ import org.apache.servicemix.http.jetty.
 import org.apache.servicemix.http.jetty.JettyContextManager;
 import org.mortbay.thread.QueuedThreadPool;
 
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
 /**
  * an HTTP JBI component
  * 
@@ -73,7 +65,7 @@ public class HttpComponent extends Defau
     /**
      * Returns the host name.
      * 
-     * @return a string contianing the host name
+     * @return a string containing the host name
      */
     public String getHost() {
         return host;
@@ -179,6 +171,8 @@ public class HttpComponent extends Defau
         tempClient.setThreadPool(btp);
         tempClient.setConnectorType(org.mortbay.jetty.client.HttpClient.CONNECTOR_SELECT_CHANNEL);
         tempClient.setTimeout(getConfiguration().getProviderExpirationTime());
+        tempClient.setSoTimeout(getConfiguration().getClientSoTimeout());
+        tempClient.setMaxConnectionsPerAddress(getConfiguration().getMaxConnectionsPerAddress());
         tempClient.start();
         return tempClient;
     }
@@ -241,7 +235,7 @@ public class HttpComponent extends Defau
                 configuration.setAuthenticationService(as);
             } catch (Throwable e) {
                 try {
-                    Class cl = Class
+                    Class<?> cl = Class
                         .forName("org.apache.servicemix.jbi.security.auth.impl.JAASAuthenticationService");
                     configuration.setAuthenticationService(cl.newInstance());
                 } catch (Throwable t) {

Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java?rev=1133867&r1=1133866&r2=1133867&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
(original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpConfiguration.java
Thu Jun  9 13:31:15 2011
@@ -120,9 +120,19 @@ public class HttpConfiguration implement
     private int consumerProcessorSuspendTime = 60000;
   	
     /***
-     * HttpProvider endpoint expiration time.
+     * HttpProvider endpoint expiration time when jettyClientPerProvider is false.
      */
     private int providerExpirationTime = 300000;
+    
+    /***
+     * HttpProvider endpoint clientSoTimeout when jettyClientPerProvider is false.
+     */
+    private int clientSoTimeout = 10000;    
+    
+    /***
+     * HttpProvider endpoint maxConnectionsPerAddress when jettyClientPerProvider is false.
+     */    
+    private int maxConnectionsPerAddress = 32;
 
     /**
      * Number of times a given HTTP request will be tried until successful. If
@@ -432,7 +442,7 @@ public class HttpConfiguration implement
      * The default behavior is that all HTTP provider endpoints use a shrared
      * Jetty client.
      * 
-     * @param jettyClientProvider <code>true</code> if HTTP providers are to
use
+     * @param jettyClientPerProvider <code>true</code> if HTTP providers are
to use
      *            individual Jetty clients
      * @org.apache.xbean.Property description="Specifies if HTTP provider endpoints share
a Jetty client or use per-endpoint Jetty clients. The default setting is
      *                            <code>false</code> meaning that all provider
@@ -579,16 +589,60 @@ public class HttpConfiguration implement
      * Sets the number of milliseconds the provider will wait for a response (read timeout).
      * The default default value for Jetty is 300000.
      *
-     * @param providerExpirationTime an int representing the number of milliseconds the Jetty
will wait for a response.
-     * @org.apache.xbean.Property description="the number of miliseconds Jetty will susspend
the processing of a request. The default is 60000."
+     * @param providerExpirationTime an int representing the number of milliseconds the Jetty
will wait for a response (read timeout).
+     * @org.apache.xbean.Property description="the number of miliseconds the provider will
wait for a response (read timeout). The default is 300000."
      */
     public void setProviderExpirationTime(int providerExpirationTime) {
         this.providerExpirationTime = providerExpirationTime;
         save();
     }
+    
+    /***
+     * Gets the number of milliseconds for soTimeout parameter of JettyClient when JettyClient
instance is shared among http:provider enpoints.
+     * @return an int representing the JettyClient soTimeout.
+     */
+    public int getClientSoTimeout() {
+        return clientSoTimeout;
+    }
+
+    /**
+     * Sets the number of milliseconds for soTimeout parameter of JettyClient when JettyClient
instance is shared among http:provider enpoints.
+     * The default default value for Jetty is 10000.
+     *
+     * @param clientSoTimeout an int representing the JettyClient soTimeout.
+     * @org.apache.xbean.Property description="the number of miliseconds representign shared
JettyClient soTimeout. The default is 10000."
+     */
+    public void setClientSoTimeout(int clientSoTimeout) {
+        this.clientSoTimeout = clientSoTimeout;
+        save();
+    }    
 
 
 
+    
+    /***
+     * Gets the number of the maximum connections per address that JettyClient creates for
each destination.
+     * 
+     * @return an int representing the JettyClient maxConnectionsPerAddress.
+     */
+    public int getMaxConnectionsPerAddress() {
+        return maxConnectionsPerAddress;
+    }
+
+    
+    /**
+     * Sets the number of the maximum connections per address that JettyClient creates for
each destination.
+     * The default default value for Jetty is 32.
+     * 
+     * @param maxConnectionsPerAddress the maxConnectionsPerAddress to set
+     * @org.apache.xbean.Property description="the number of the maximum connections per
address that JettyClient creates for each destination. The default is 32."
+     * 
+     */
+    public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress) {
+        this.maxConnectionsPerAddress = maxConnectionsPerAddress;
+        save();
+    }
+
     /**
      * Gets the number of times a request will be tried before an error is
      * created.
@@ -723,9 +777,10 @@ public class HttpConfiguration implement
         setProperty(componentName + ".jettyManagement", Boolean.toString(jettyManagement));
         setProperty(componentName + ".connectorMaxIdleTime", Integer.toString(connectorMaxIdleTime));
         setProperty(componentName + ".soLingerTime", Integer.toString(soLingerTime));
-        setProperty(componentName + ".consumerProcessorSuspendTime", Integer
-            .toString(consumerProcessorSuspendTime));
+        setProperty(componentName + ".consumerProcessorSuspendTime", Integer.toString(consumerProcessorSuspendTime));
         setProperty(componentName + ".providerExpirationTime", Integer.toString(providerExpirationTime));
+        setProperty(componentName + ".clientSoTimeout", Integer.toString(clientSoTimeout));
+        setProperty(componentName + ".maxConnectionsPerAddress", Integer.toString(maxConnectionsPerAddress));
         setProperty(componentName + ".retryCount", Integer.toString(retryCount));
         setProperty(componentName + ".proxyHost", proxyHost);
         setProperty(componentName + ".proxyPort", Integer.toString(proxyPort));
@@ -832,6 +887,14 @@ public class HttpConfiguration implement
             providerExpirationTime = Integer.parseInt(properties
                 .getProperty(componentName + ".providerExpirationTime"));
         }
+        if (properties.getProperty(componentName + ".clientSoTimeout") != null) {
+        	clientSoTimeout = Integer.parseInt(properties
+                .getProperty(componentName + ".clientSoTimeout"));
+        }
+        if (properties.getProperty(componentName + ".maxConnectionsPerAddress") != null)
{
+            maxConnectionsPerAddress = Integer.parseInt(properties
+                .getProperty(componentName + ".maxConnectionsPerAddress"));
+        }
         if (properties.getProperty(componentName + ".retryCount") != null) {
             retryCount = Integer.parseInt(properties.getProperty(componentName + ".retryCount"));
         }

Modified: servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java?rev=1133867&r1=1133866&r2=1133867&view=diff
==============================================================================
--- servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
(original)
+++ servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/endpoints/HttpProviderEndpoint.java
Thu Jun  9 13:31:15 2011
@@ -16,32 +16,14 @@
  */
 package org.apache.servicemix.http.endpoints;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-import java.security.SecureRandom;
-
-import javax.jbi.messaging.ExchangeStatus;
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.NormalizedMessage;
-import javax.jbi.servicedesc.ServiceEndpoint;
-import javax.jbi.management.DeploymentException;
-import javax.xml.namespace.QName;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.KeyManager;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-
-import org.apache.servicemix.common.JbiConstants;
 import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.JbiConstants;
 import org.apache.servicemix.common.ServiceUnit;
-import org.apache.servicemix.common.security.KeystoreManager;
 import org.apache.servicemix.common.endpoints.ProviderEndpoint;
+import org.apache.servicemix.common.security.KeystoreManager;
 import org.apache.servicemix.http.HttpComponent;
-import org.apache.servicemix.http.HttpEndpointType;
 import org.apache.servicemix.http.HttpConfiguration;
+import org.apache.servicemix.http.HttpEndpointType;
 import org.apache.servicemix.http.SslParameters;
 import org.apache.servicemix.http.jetty.SmxHttpExchange;
 import org.mortbay.jetty.client.Address;
@@ -49,8 +31,21 @@ import org.mortbay.jetty.client.HttpClie
 import org.mortbay.jetty.client.security.ProxyAuthorization;
 import org.mortbay.jetty.client.security.Realm;
 import org.mortbay.jetty.client.security.SimpleRealmResolver;
-import org.mortbay.thread.QueuedThreadPool;
 import org.mortbay.resource.Resource;
+import org.mortbay.thread.QueuedThreadPool;
+
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.net.ssl.*;
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.SecureRandom;
 
 /**
  * A plain HTTP provider. This type of endpoint can be used to send non-SOAP requests to
HTTP endpoints.
@@ -65,6 +60,7 @@ public class HttpProviderEndpoint extend
     private String locationURI;
     private int clientSoTimeout = 60000;
     private int providerExpirationTime = 300000;
+    private int maxConnectionsPerAddress = 32;
     private HttpClient jettyClient;
     private boolean ownClient = false;
     private String principal;
@@ -267,12 +263,17 @@ public class HttpProviderEndpoint extend
             }
             SmxHttpExchange httpEx = new Exchange(exchange);
             marshaler.createRequest(exchange, nm, httpEx);
-            getConnectionPool().send(httpEx);
+            jettyClient.send(httpEx);
         }
     }
+    
+    @Override
+    public synchronized void start() throws Exception {
+    	getConnectionPool();
+    }
 
-
-    public void stop() throws Exception {
+    @Override
+    public synchronized void stop() throws Exception {
         if (ownClient && jettyClient != null) {
             jettyClient.stop();
             jettyClient = null;
@@ -331,6 +332,7 @@ public class HttpProviderEndpoint extend
                 }
                 jettyClient.setSoTimeout(getClientSoTimeout());
                 jettyClient.setTimeout(getProviderExpirationTime());
+                jettyClient.setMaxConnectionsPerAddress(getMaxConnectionsPerAddress());
                 if (principal != null && credentials != null) {
                     jettyClient.setRealmResolver(new SimpleRealmResolver(new Realm() {
                         public String getPrincipal() {
@@ -351,10 +353,6 @@ public class HttpProviderEndpoint extend
                 jettyClient = comp.getConnectionPool();
             }
         }
-        if (!ownClient) {
-            // Always reset the SO timeout, in case the client is shared
-            jettyClient.setSoTimeout(getClientSoTimeout());
-        }
         return jettyClient;
     }
 
@@ -386,6 +384,22 @@ public class HttpProviderEndpoint extend
     public void setProviderExpirationTime(int providerExpirationTime) {
         this.providerExpirationTime = providerExpirationTime;
     }
+    
+    public int getMaxConnectionsPerAddress() {
+        return maxConnectionsPerAddress;
+    }
+
+    /**
+     * Sets the number of the maximum connections per address that JettyClient creates for
each destination.
+     * The default default value for Jetty is 32.
+     * 
+     * @param maxConnectionsPerAddress the maxConnectionsPerAddress to set
+     * @org.apache.xbean.Property description="the number of the maximum connections per
address that JettyClient creates for each destination. The default is 32."
+     * 
+     */
+    public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress) {
+        this.maxConnectionsPerAddress = maxConnectionsPerAddress;
+    }
 
     public void validate() throws DeploymentException {
         super.validate();



Mime
View raw message