]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1526] configure http connection pool values for wagon http.
authorOlivier Lamy <olamy@apache.org>
Fri, 30 Sep 2011 13:36:56 +0000 (13:36 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 30 Sep 2011 13:36:56 +0000 (13:36 +0000)
add basic services.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1177654 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
archiva-modules/archiva-base/archiva-converter/src/test/java/org/apache/archiva/converter/mock/MockArchivaAdministration.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/admin/ArchivaAdministration.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/NetworkConfiguration.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/ArchivaAdministrationStub.java
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/mock/MockArchivaAdministration.java
pom.xml

index 763e5ee6fa4778a8d89abbc1e538da2d03fa9cc3..b867ef7d8bd26b7e8edc5a094e5fe1f1491483d4 100644 (file)
           <description>
             The organisation info.
           </description>
-        </field>  
+        </field>
+        <field>
+          <name>networkConfiguration</name>
+          <version>1.4.0+</version>
+          <association>
+            <type>NetworkConfiguration</type>
+            <multiplicity>1</multiplicity>
+          </association>
+          <description>
+            The NetworkConfiguration .
+          </description>
+        </field>
       </fields>
       <codeSegments>
         <codeSegment>
       </fields>
     </class>
 
+    <class>
+      <name>NetworkConfiguration</name>
+      <version>1.4.0+</version>
+      <description>
+        The network configuration for external http request to repositories.
+      </description>
+      <fields>
+        <field>
+          <name>maxTotal</name>
+          <description>maximum total external http connections.</description>
+          <version>1.4.0+</version>
+          <type>int</type>
+          <defaultValue>30</defaultValue>
+        </field>
+        <field>
+          <name>maxTotalPerHost</name>
+          <description>maximum total external http connections per host</description>
+          <version>1.4.0+</version>
+          <type>int</type>
+          <defaultValue>30</defaultValue>
+        </field>
+        <field>
+          <name>usePooling</name>
+          <description>use or not http connection pooling default true</description>
+          <version>1.4.0+</version>
+          <type>boolean</type>
+          <defaultValue>true</defaultValue>
+        </field>
+      </fields>
+    </class>
+
   </classes>
 </model>
 
index fa34784dbb21f1402739d94cad25f9435f6e8c21..93e6c33ac2334671cb5a87fc0c500c48f2f02f55 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
 import org.apache.archiva.admin.model.beans.FileType;
 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
+import org.apache.archiva.admin.model.beans.NetworkConfiguration;
 import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
 
@@ -160,4 +161,16 @@ public class MockArchivaAdministration
     {
 
     }
+
+    public NetworkConfiguration getNetworkConfiguration()
+        throws RepositoryAdminException
+    {
+        return null;
+    }
+
+    public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
+        throws RepositoryAdminException
+    {
+
+    }
 }
index bfd271ef48679cf8a88ef4c2ffae62c0fe7cf862..975b045f3c8f453d114324dd37f6addd695eb223 100644 (file)
@@ -22,6 +22,7 @@ import org.apache.archiva.admin.model.AuditInformation;
 import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.FileType;
 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
+import org.apache.archiva.admin.model.beans.NetworkConfiguration;
 import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
 
@@ -97,4 +98,10 @@ public interface ArchivaAdministration
     void updateUiConfiguration( UiConfiguration uiConfiguration )
         throws RepositoryAdminException;
 
+    NetworkConfiguration getNetworkConfiguration()
+        throws RepositoryAdminException;
+
+    void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
+        throws RepositoryAdminException;
+
 }
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/NetworkConfiguration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/NetworkConfiguration.java
new file mode 100644 (file)
index 0000000..26e732d
--- /dev/null
@@ -0,0 +1,97 @@
+package org.apache.archiva.admin.model.beans;
+/*
+ * 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 javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+@XmlRootElement( name = "networkConfiguration" )
+public class NetworkConfiguration
+    implements Serializable
+{
+    /**
+     * maximum total external http connections.
+     */
+    private int maxTotal = 30;
+
+    /**
+     * maximum total external http connections per host.
+     */
+    private int maxTotalPerHost = 30;
+
+    private boolean usePooling = true;
+
+    public NetworkConfiguration()
+    {
+        // no op
+    }
+
+    public NetworkConfiguration( int maxTotal, int maxTotalPerHost, boolean usePooling )
+    {
+        this.maxTotal = maxTotal;
+        this.maxTotalPerHost = maxTotalPerHost;
+        this.usePooling = usePooling;
+    }
+
+    public int getMaxTotal()
+    {
+        return maxTotal;
+    }
+
+    public void setMaxTotal( int maxTotal )
+    {
+        this.maxTotal = maxTotal;
+    }
+
+    public int getMaxTotalPerHost()
+    {
+        return maxTotalPerHost;
+    }
+
+    public void setMaxTotalPerHost( int maxTotalPerHost )
+    {
+        this.maxTotalPerHost = maxTotalPerHost;
+    }
+
+    public boolean isUsePooling()
+    {
+        return usePooling;
+    }
+
+    public void setUsePooling( boolean usePooling )
+    {
+        this.usePooling = usePooling;
+    }
+
+    @Override
+    public String toString()
+    {
+        final StringBuilder sb = new StringBuilder();
+        sb.append( "NetworkConfiguration" );
+        sb.append( "{maxTotal=" ).append( maxTotal );
+        sb.append( ", maxTotalPerHost=" ).append( maxTotalPerHost );
+        sb.append( ", usePooling=" ).append( usePooling );
+        sb.append( '}' );
+        return sb.toString();
+    }
+}
index a2f4721dad03520247e1965770e10f340563c1b5..232f246cdebd0d807f4af4248ab72f5a83a9f0bc 100644 (file)
           </exclusion>
         </exclusions>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>commons-logging</groupId>
+          <artifactId>commons-logging</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+        <exclusions>
+          <exclusion>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+          </exclusion>
+        </exclusions>
+    </dependency>
     <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-context-support</artifactId>
index 8cb88007f721df16b90eef4baf6f876f20fcabe8..6a6999c8e90d78aaeabd75905834ce10188fb967 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
 import org.apache.archiva.admin.model.beans.FileType;
 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
+import org.apache.archiva.admin.model.beans.NetworkConfiguration;
 import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
@@ -32,6 +33,8 @@ import org.apache.archiva.configuration.Configuration;
 import org.apache.archiva.configuration.UserInterfaceOptions;
 import org.apache.archiva.configuration.WebappConfiguration;
 import org.apache.commons.lang.StringUtils;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.maven.wagon.providers.http.HttpWagon;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -56,7 +59,6 @@ public class DefaultArchivaAdministration
                 new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
         }
         return legacyArtifactPaths;
-
     }
 
     public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
@@ -323,7 +325,48 @@ public class DefaultArchivaAdministration
 
     }
 
-//-------------------------
+    public NetworkConfiguration getNetworkConfiguration()
+        throws RepositoryAdminException
+    {
+        org.apache.archiva.configuration.NetworkConfiguration networkConfiguration =
+            getArchivaConfiguration().getConfiguration().getNetworkConfiguration();
+
+        if ( networkConfiguration == null )
+        {
+            return null;
+        }
+        return new BeanReplicator().replicateBean( networkConfiguration, NetworkConfiguration.class );
+    }
+
+    public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        if ( networkConfiguration == null )
+        {
+            configuration.setNetworkConfiguration( null );
+            // back to default values
+            HttpWagon.setUseClientManagerPooled( true );
+            ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager();
+            threadSafeClientConnManager.setDefaultMaxPerRoute( 30 );
+            threadSafeClientConnManager.setMaxTotal( 30 );
+            HttpWagon.setConnectionManagerPooled( threadSafeClientConnManager );
+
+        }
+        else
+        {
+            HttpWagon.setUseClientManagerPooled( networkConfiguration.isUsePooling() );
+            ThreadSafeClientConnManager threadSafeClientConnManager = new ThreadSafeClientConnManager();
+            threadSafeClientConnManager.setDefaultMaxPerRoute( networkConfiguration.getMaxTotalPerHost() );
+            threadSafeClientConnManager.setMaxTotal( networkConfiguration.getMaxTotal() );
+            HttpWagon.setConnectionManagerPooled( threadSafeClientConnManager );
+            configuration.setNetworkConfiguration( new BeanReplicator().replicateBean( networkConfiguration,
+                                                                                       org.apache.archiva.configuration.NetworkConfiguration.class ) );
+        }
+        saveConfiguration( configuration );
+    }
+
+    //-------------------------
     //
     //-------------------------
 
index 1a3e153fad8592c28c245680278fb0fa8b05c14f..59165ba5c222aaa5500b68212bd7017baa48eae7 100644 (file)
@@ -22,6 +22,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
 import org.apache.archiva.admin.model.beans.FileType;
 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
+import org.apache.archiva.admin.model.beans.NetworkConfiguration;
 import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
@@ -219,4 +220,16 @@ public class ArchivaAdministrationTest
         assertFalse( ui.isAppletFindEnabled() );
         assertFalse( ui.isShowFindArtifacts() );
     }
+
+    @Test
+    public void networkConfiguration()
+        throws Exception
+    {
+        NetworkConfiguration networkConfiguration = archivaAdministration.getNetworkConfiguration();
+        assertNotNull( networkConfiguration );
+
+        assertTrue( networkConfiguration.isUsePooling() );
+        assertEquals( 30, networkConfiguration.getMaxTotal() );
+        assertEquals( 30, networkConfiguration.getMaxTotalPerHost() );
+    }
 }
index 671a48598272100e6eb85890447ffc57d06290a6..57041e32defe9fd03fe03ff9f9555d6179ded836 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
 import org.apache.archiva.admin.model.beans.FileType;
 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
+import org.apache.archiva.admin.model.beans.NetworkConfiguration;
 import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
 import org.apache.archiva.configuration.ArchivaConfiguration;
@@ -174,6 +175,19 @@ public class ArchivaAdministrationStub
     public void updateUiConfiguration( UiConfiguration uiConfiguration )
         throws RepositoryAdminException
     {
-        //To change body of implemented methods use File | Settings | File Templates.
+
+    }
+
+
+    public NetworkConfiguration getNetworkConfiguration()
+        throws RepositoryAdminException
+    {
+        return null;
+    }
+
+    public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
+        throws RepositoryAdminException
+    {
+
     }
 }
index f87f1b7f933e9ec16b2fbdbfdfa14a1f8d1f8bae..2cb62ef7864a9a173cf1e0f817381f01e53b9cf8 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
 import org.apache.archiva.admin.model.beans.FileType;
 import org.apache.archiva.admin.model.beans.LegacyArtifactPath;
+import org.apache.archiva.admin.model.beans.NetworkConfiguration;
 import org.apache.archiva.admin.model.beans.OrganisationInformation;
 import org.apache.archiva.admin.model.beans.UiConfiguration;
 import org.apache.archiva.configuration.ArchivaConfiguration;
@@ -175,4 +176,16 @@ public class MockArchivaAdministration
     {
 
     }
+
+    public NetworkConfiguration getNetworkConfiguration()
+        throws RepositoryAdminException
+    {
+        return null;
+    }
+
+    public void setNetworkConfiguration( NetworkConfiguration networkConfiguration )
+        throws RepositoryAdminException
+    {
+
+    }
 }
diff --git a/pom.xml b/pom.xml
index 9a8b9cf02f911084a8ccf79ca71832709fe521b1..0f18f50861352e1ac37d9c805e4951ddccf97128 100644 (file)
--- a/pom.xml
+++ b/pom.xml
           </exclusion>
         </exclusions>
       </dependency>
+      <dependency>
+        <groupId>org.apache.httpcomponents</groupId>
+        <artifactId>httpclient</artifactId>
+        <version>4.1.2</version>
+        <exclusions>
+          <exclusion>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
       <dependency>
         <groupId>org.apache.maven.wagon</groupId>
         <artifactId>wagon-provider-api</artifactId>