]> source.dussan.org Git - archiva.git/commitdiff
[MRM-465] (Load Testing) When asking for pages that require the effective-pom in...
authorJoakim Erdfelt <joakime@apache.org>
Mon, 13 Aug 2007 19:40:06 +0000 (19:40 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Mon, 13 Aug 2007 19:40:06 +0000 (19:40 +0000)
Added an ehcache around the effective-pom resolution process.

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

archiva-base/archiva-repository-layer/pom.xml
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilter.java
archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components-fragment.xml [new file with mode: 0644]

index f8c47986f524a9dd91cb109802adb88db68a268d..b2263d06aa04e6551da93b4e3c1330e92dae27d1 100644 (file)
               <goal>descriptor</goal>
             </goals>
           </execution>
+          <execution>
+            <id>merge</id>
+            <goals>
+              <goal>merge-descriptors</goal>
+            </goals>
+            <configuration>
+              <descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
+              <descriptors>
+                <descriptor>${basedir}/src/main/resources/META-INF/plexus/components-fragment.xml</descriptor>
+                <descriptor>${project.build.directory}/generated-resources/plexus/META-INF/plexus/components.xml</descriptor>
+              </descriptors>
+            </configuration>
+          </execution>
         </executions>
       </plugin>
     </plugins>
index cb7768f3b1457a79e8bfa83a822d867b26aee915..8a5b8f8befa3c92c5419f5b87cccd908edfbbec6 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.maven.archiva.repository.project.ProjectModelException;
 import org.apache.maven.archiva.repository.project.ProjectModelFilter;
 import org.apache.maven.archiva.repository.project.ProjectModelMerge;
 import org.apache.maven.archiva.repository.project.ProjectModelResolverFactory;
+import org.codehaus.plexus.cache.Cache;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.logging.console.ConsoleLogger;
@@ -56,6 +57,11 @@ public class EffectiveProjectModelFilter
      * @plexus.requirement
      */
     private ProjectModelResolverFactory resolverFactory;
+    
+    /**
+     * @plexus.requirement role-hint="effective-project-cache"
+     */
+    private Cache effectiveProjectCache;
 
     /**
      * Take the provided {@link ArchivaProjectModel} and build the effective {@link ArchivaProjectModel}.
@@ -81,9 +87,21 @@ public class EffectiveProjectModelFilter
         {
             throw new IllegalStateException( "Unable to build effective pom with no project model resolvers defined." );
         }
+        
+        ArchivaProjectModel effectiveProject;
+        String projectKey = toProjectKey( project );
+        
+        synchronized( effectiveProjectCache )
+        {
+            if( effectiveProjectCache.hasKey( projectKey ) )
+            {
+                effectiveProject = (ArchivaProjectModel) effectiveProjectCache.get( projectKey );
+                return effectiveProject;
+            }
+        }
 
         // Clone submitted project (so that we don't mess with it) 
-        ArchivaProjectModel effectiveProject = ArchivaModelCloner.clone( project );
+        effectiveProject = ArchivaModelCloner.clone( project );
 
         // Setup Expression Evaluation pieces.
         effectiveProject = expressionFilter.filter( effectiveProject );
@@ -95,6 +113,11 @@ public class EffectiveProjectModelFilter
 
         // Resolve dependency versions from dependency management.
         applyDependencyManagement( effectiveProject );
+        
+        synchronized( effectiveProjectCache )
+        {
+            effectiveProjectCache.put( projectKey, effectiveProject );
+        }
 
         // Return what we got.
         return effectiveProject;
@@ -157,6 +180,16 @@ public class EffectiveProjectModelFilter
             VersionedReference parentRef = pom.getParentProject();
 
             getLogger().debug( "Has parent: " + parentRef );
+            
+            String pomKey = VersionedReference.toKey( parentRef );
+            
+            synchronized( effectiveProjectCache )
+            {
+                if( effectiveProjectCache.hasKey( pomKey ) )
+                {
+                    return (ArchivaProjectModel) effectiveProjectCache.get( pomKey );
+                }
+            }
 
             // Find parent using resolvers.
             ArchivaProjectModel parentProject = this.resolverFactory.getCurrentResolverStack().findProject( parentRef );
@@ -173,6 +206,11 @@ public class EffectiveProjectModelFilter
                 // TODO: Document this via monitor.
                 mixedProject = mixinSuperPom( pom );
             }
+            
+            synchronized( effectiveProjectCache )
+            {
+                effectiveProjectCache.put( pomKey, mixedProject );
+            }
         }
         else
         {
@@ -187,7 +225,7 @@ public class EffectiveProjectModelFilter
 
             mixedProject = mixinSuperPom( pom );
         }
-
+        
         return mixedProject;
     }
 
@@ -232,4 +270,15 @@ public class EffectiveProjectModelFilter
 
         return key.toString();
     }
+    
+    private String toProjectKey( ArchivaProjectModel project )
+    {
+        StringBuffer key = new StringBuffer();
+
+        key.append( project.getGroupId() ).append( ":" );
+        key.append( project.getArtifactId() ).append( ":" );
+        key.append( project.getVersion() );
+
+        return key.toString();
+    }
 }
diff --git a/archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components-fragment.xml b/archiva-base/archiva-repository-layer/src/main/resources/META-INF/plexus/components-fragment.xml
new file mode 100644 (file)
index 0000000..ed63a3b
--- /dev/null
@@ -0,0 +1,25 @@
+<component-set>
+  <components>
+    <component>
+      <role>org.codehaus.plexus.cache.Cache</role>
+      <role-hint>effective-project-cache</role-hint>
+      <implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
+      <description>Effective Project Cache</description>
+      <configuration>
+        <disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
+        <disk-persistent>true</disk-persistent>
+        <disk-store-path>${java.io.tmpdir}/archiva/effectiveproject</disk-store-path>
+        <eternal>true</eternal>
+        <max-elements-in-memory>1000</max-elements-in-memory>
+        <memory-eviction-policy>LRU</memory-eviction-policy>
+        <name>effective-project-cache</name>
+        <overflow-to-disk>false</overflow-to-disk>
+        <!-- TODO: Adjust the time to live to be more sane (ie: huge 4+ hours) -->
+        <!-- 45 minutes = 2700 seconds -->
+        <time-to-idle-seconds>2700</time-to-idle-seconds>
+        <!-- 30 minutes = 1800 seconds  -->
+        <time-to-live-seconds>1800</time-to-live-seconds>
+      </configuration>
+    </component>
+  </components>
+</component-set>