continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1414515 - in /continuum/trunk: ./ continuum-distributed/continuum-distributed-commons/ continuum-distributed/continuum-distributed-commons/src/main/java/org/apache/continuum/distributed/commons/utils/ continuum-distributed/continuum-distri...
Date Wed, 28 Nov 2012 02:55:30 GMT
Author: brett
Date: Wed Nov 28 02:55:28 2012
New Revision: 1414515

URL: http://svn.apache.org/viewvc?rev=1414515&view=rev
Log:
[CONTINUUM-2693] avoid file handle leak with distributed builds

ContinuumXmlRpcBinder is a copy of the ApacheBinder class by James Dumay from Atlassian XMLRPC
Binder 0.11. It has been modified to maintain a singleton instance of HttpClient. License
header remains intact.

By reusing the binder implementation with a thread-safe version of HttpClient, connections
should be pooled but properly managed. With the default HttpClient (which uses SimpleHttpConnectionManager),
connections are not closed on release and can accumulate over time.

Added:
    continuum/trunk/continuum-distributed/continuum-distributed-commons/src/main/java/org/apache/continuum/distributed/commons/utils/ContinuumXmlRpcBinder.java
  (with props)
Modified:
    continuum/trunk/continuum-distributed/continuum-distributed-commons/pom.xml
    continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/pom.xml
    continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java
    continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/pom.xml
    continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/pom.xml
    continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java
    continuum/trunk/pom.xml

Modified: continuum/trunk/continuum-distributed/continuum-distributed-commons/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-commons/pom.xml?rev=1414515&r1=1414514&r2=1414515&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-commons/pom.xml (original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-commons/pom.xml Wed Nov 28
02:55:28 2012
@@ -28,4 +28,26 @@
   <modelVersion>4.0.0</modelVersion>
   <artifactId>continuum-distributed-commons</artifactId>
   <name>Continuum :: Distributed Build :: Commons</name>
+  <dependencies>
+    <dependency>
+      <groupId>com.atlassian.xmlrpc</groupId>
+      <artifactId>atlassian-xmlrpc-binder</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.atlassian.xmlrpc</groupId>
+      <artifactId>atlassian-xmlrpc-binder-support</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.xmlrpc</groupId>
+      <artifactId>xmlrpc-client</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+  </dependencies>
 </project>

Added: continuum/trunk/continuum-distributed/continuum-distributed-commons/src/main/java/org/apache/continuum/distributed/commons/utils/ContinuumXmlRpcBinder.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-commons/src/main/java/org/apache/continuum/distributed/commons/utils/ContinuumXmlRpcBinder.java?rev=1414515&view=auto
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-commons/src/main/java/org/apache/continuum/distributed/commons/utils/ContinuumXmlRpcBinder.java
(added)
+++ continuum/trunk/continuum-distributed/continuum-distributed-commons/src/main/java/org/apache/continuum/distributed/commons/utils/ContinuumXmlRpcBinder.java
Wed Nov 28 02:55:28 2012
@@ -0,0 +1,135 @@
+package org.apache.continuum.distributed.commons.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import com.atlassian.xmlrpc.Binder;
+import com.atlassian.xmlrpc.BinderTypeFactory;
+import com.atlassian.xmlrpc.BindingException;
+import com.atlassian.xmlrpc.ConnectionInfo;
+import com.atlassian.xmlrpc.ServiceObject;
+import com.atlassian.xmlrpc.XmlRpcClientProvider;
+import com.atlassian.xmlrpc.XmlRpcInvocationHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
+
+import java.lang.reflect.Proxy;
+import java.net.URL;
+import java.util.Vector;
+
+/**
+ * Used to bind the given XML-RPC service to an instance of
+ * the given interface type.
+ *
+ * This implementation uses the Apache XML-RPC client.
+ *
+ * This is derived from ApacheBinder from the atlassian-xmlrpc-binder project. In this version,
we customise the
+ * transport used for better connection management. It is thread-safe and should be reused.
+ *
+ * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
+ */
+public class ContinuumXmlRpcBinder
+    implements Binder
+{
+    private final HttpClient httpClient;
+
+    private static ContinuumXmlRpcBinder binder = new ContinuumXmlRpcBinder();
+
+    private ContinuumXmlRpcBinder()
+    {
+        this.httpClient = new HttpClient( new MultiThreadedHttpConnectionManager() );
+    }
+
+    public <T> T bind( Class<T> bindClass, URL url )
+        throws BindingException
+    {
+        return bind( bindClass, url, new ConnectionInfo() );
+    }
+
+    public <T> T bind( Class<T> bindClass, URL url, ConnectionInfo connectionInfo
)
+        throws BindingException
+    {
+        if ( !bindClass.isInterface() )
+        {
+            throw new BindingException( "Class " + bindClass.getName() + "is not an interface"
);
+        }
+        ServiceObject serviceObject = bindClass.getAnnotation( ServiceObject.class );
+        if ( serviceObject == null )
+        {
+            throw new BindingException( "Could not find ServiceObject annotation on " + bindClass.getName()
);
+        }
+        final XmlRpcClient client = getXmlRpcClient( url, connectionInfo );
+
+        XmlRpcInvocationHandler handler = new XmlRpcInvocationHandler( new XmlRpcClientProvider()
+        {
+            public Object execute( String serviceName, String methodName, Vector arguments
)
+                throws BindingException
+            {
+                try
+                {
+                    return client.execute( serviceName + "." + methodName, arguments );
+                }
+                catch ( XmlRpcException e )
+                {
+                    throw new BindingException( e );
+                }
+            }
+        } );
+
+        return (T) Proxy.newProxyInstance( getClass().getClassLoader(), new Class[]{bindClass},
handler );
+    }
+
+    private XmlRpcClient getXmlRpcClient( URL url, ConnectionInfo connectionInfo )
+    {
+        XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
+        clientConfig.setServerURL( url );
+        clientConfig.setEnabledForExceptions( true );
+
+        if ( connectionInfo != null )
+        {
+            clientConfig.setBasicUserName( connectionInfo.getUsername() );
+            clientConfig.setBasicPassword( connectionInfo.getPassword() );
+            clientConfig.setBasicEncoding( connectionInfo.getEncoding() );
+            clientConfig.setGzipCompressing( connectionInfo.isGzip() );
+            clientConfig.setGzipRequesting( connectionInfo.isGzip() );
+            clientConfig.setReplyTimeout( connectionInfo.getTimeout() );
+            clientConfig.setConnectionTimeout( connectionInfo.getTimeout() );
+            clientConfig.setTimeZone( connectionInfo.getTimeZone() );
+        }
+
+        final XmlRpcClient client = new XmlRpcClient();
+        client.setTypeFactory( new BinderTypeFactory( client ) );
+        XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory( client
);
+        // Alternative - use simple connection manager, but make sure it closes the connection
each time
+        // This would be set here since it would not be thread-safe
+//        factory.setHttpClient( new HttpClient( new SimpleHttpConnectionManager( true )
) );
+        factory.setHttpClient( httpClient );
+        client.setConfig( clientConfig );
+        return client;
+    }
+
+    public static ContinuumXmlRpcBinder getInstance()
+    {
+        return binder;
+    }
+}

Propchange: continuum/trunk/continuum-distributed/continuum-distributed-commons/src/main/java/org/apache/continuum/distributed/commons/utils/ContinuumXmlRpcBinder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/pom.xml?rev=1414515&r1=1414514&r2=1414515&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/pom.xml
(original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/pom.xml
Wed Nov 28 02:55:28 2012
@@ -36,17 +36,12 @@ under the License.
     <dependency>
       <groupId>org.apache.continuum</groupId>
       <artifactId>continuum-distributed-commons</artifactId>
-      <version>${project.version}</version>
     </dependency>
     <dependency>
       <groupId>com.atlassian.xmlrpc</groupId>
       <artifactId>atlassian-xmlrpc-binder</artifactId>
     </dependency>
     <dependency>
-      <groupId>com.atlassian.xmlrpc</groupId>
-      <artifactId>atlassian-xmlrpc-binder-client-apache</artifactId>
-    </dependency>
-    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>

Modified: continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java?rev=1414515&r1=1414514&r2=1414515&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java
(original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java
Wed Nov 28 02:55:28 2012
@@ -19,11 +19,11 @@ package org.apache.continuum.distributed
  * under the License.
  */
 
-import com.atlassian.xmlrpc.ApacheBinder;
 import com.atlassian.xmlrpc.Binder;
 import com.atlassian.xmlrpc.BindingException;
 import com.atlassian.xmlrpc.ConnectionInfo;
 import org.apache.continuum.distributed.commons.utils.ContinuumDistributedUtil;
+import org.apache.continuum.distributed.commons.utils.ContinuumXmlRpcBinder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -52,7 +52,7 @@ public class MasterBuildAgentTransportCl
     public MasterBuildAgentTransportClient( URL serviceUrl, String login, String password
)
         throws Exception
     {
-        Binder binder = new ApacheBinder();
+        Binder binder = ContinuumXmlRpcBinder.getInstance();
 
         ConnectionInfo connectionInfo = new ConnectionInfo();
         connectionInfo.setUsername( login );

Modified: continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/pom.xml?rev=1414515&r1=1414514&r2=1414515&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/pom.xml
(original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/pom.xml
Wed Nov 28 02:55:28 2012
@@ -40,7 +40,6 @@ under the License.
     <dependency>
       <groupId>org.apache.continuum</groupId>
       <artifactId>continuum-distributed-commons</artifactId>
-      <version>${project.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.continuum</groupId>

Modified: continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/pom.xml?rev=1414515&r1=1414514&r2=1414515&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/pom.xml
(original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/pom.xml
Wed Nov 28 02:55:28 2012
@@ -31,15 +31,15 @@ under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.continuum</groupId>
-      <artifactId>continuum-distributed-slave-api</artifactId>
+      <artifactId>continuum-distributed-commons</artifactId>
     </dependency>
     <dependency>
-      <groupId>com.atlassian.xmlrpc</groupId>
-      <artifactId>atlassian-xmlrpc-binder</artifactId>
+      <groupId>org.apache.continuum</groupId>
+      <artifactId>continuum-distributed-slave-api</artifactId>
     </dependency>
     <dependency>
       <groupId>com.atlassian.xmlrpc</groupId>
-      <artifactId>atlassian-xmlrpc-binder-client-apache</artifactId>
+      <artifactId>atlassian-xmlrpc-binder</artifactId>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>

Modified: continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java?rev=1414515&r1=1414514&r2=1414515&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java
(original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java
Wed Nov 28 02:55:28 2012
@@ -19,10 +19,10 @@ package org.apache.continuum.distributed
  * under the License.
  */
 
-import com.atlassian.xmlrpc.ApacheBinder;
 import com.atlassian.xmlrpc.Binder;
 import com.atlassian.xmlrpc.BindingException;
 import com.atlassian.xmlrpc.ConnectionInfo;
+import org.apache.continuum.distributed.commons.utils.ContinuumXmlRpcBinder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,7 +53,7 @@ public class SlaveBuildAgentTransportCli
     public SlaveBuildAgentTransportClient( URL serviceUrl, String login, String password
)
         throws Exception
     {
-        Binder binder = new ApacheBinder();
+        Binder binder = ContinuumXmlRpcBinder.getInstance();
 
         ConnectionInfo connectionInfo = new ConnectionInfo();
         connectionInfo.setUsername( login );

Modified: continuum/trunk/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/pom.xml?rev=1414515&r1=1414514&r2=1414515&view=diff
==============================================================================
--- continuum/trunk/pom.xml (original)
+++ continuum/trunk/pom.xml Wed Nov 28 02:55:28 2012
@@ -747,33 +747,29 @@
       </dependency>
       <dependency>
         <groupId>com.atlassian.xmlrpc</groupId>
-        <artifactId>atlassian-xmlrpc-binder</artifactId>
+        <artifactId>atlassian-xmlrpc-binder-support</artifactId>
         <version>${atlassian.xmlrpc.binder.version}</version>
         <exclusions>
           <exclusion>
-            <groupId>commons-logging</groupId>
-            <artifactId>commons-logging</artifactId>
+            <groupId>xml-apis</groupId>
+            <artifactId>xml-apis</artifactId>
           </exclusion>
         </exclusions>
       </dependency>
       <dependency>
         <groupId>com.atlassian.xmlrpc</groupId>
-        <artifactId>atlassian-xmlrpc-binder-server-spring</artifactId>
+        <artifactId>atlassian-xmlrpc-binder</artifactId>
         <version>${atlassian.xmlrpc.binder.version}</version>
         <exclusions>
           <exclusion>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
           </exclusion>
-          <exclusion>
-            <groupId>xml-apis</groupId>
-            <artifactId>xml-apis</artifactId>
-          </exclusion>
         </exclusions>
       </dependency>
       <dependency>
         <groupId>com.atlassian.xmlrpc</groupId>
-        <artifactId>atlassian-xmlrpc-binder-client-apache</artifactId>
+        <artifactId>atlassian-xmlrpc-binder-server-spring</artifactId>
         <version>${atlassian.xmlrpc.binder.version}</version>
         <exclusions>
           <exclusion>
@@ -885,6 +881,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.continuum</groupId>
+        <artifactId>continuum-distributed-commons</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.continuum</groupId>
         <artifactId>continuum-distributed-slave-api</artifactId>
         <version>${project.version}</version>
       </dependency>
@@ -1350,6 +1351,12 @@
         <groupId>commons-httpclient</groupId>
         <artifactId>commons-httpclient</artifactId>
         <version>3.1</version>
+        <exclusions>
+          <exclusion>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+          </exclusion>
+        </exclusions>
       </dependency>
       <dependency>
         <groupId>org.codehaus.redback</groupId>



Mime
View raw message