Author: cstamas Date: Mon Dec 5 15:36:56 2011 New Revision: 1210500 URL: http://svn.apache.org/viewvc?rev=1210500&view=rev Log: Performance/locking improvements.
* VersionUtils was syncing on an already thread safe (compiled) Pattern unnecessary, GAV constructor calls into this, causing problem with when bursting GAV creations unnecessary. * DefaultArtifactPackagingMapper getPackaging2extensionMapping() was synchronized only to be able to construct the Map on 1st invocation. On frequent getExtensionForPackaging() method calls, this may cause congestion. Modified: maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/VersionUtils.java Modified: maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java?rev=1210500&r1=1210499&r2=1210500&view=diff ============================================================================== --- maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java (original) +++ maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/DefaultArtifactPackagingMapper.java Mon Dec 5 15:36:56 2011 @@ -34,7 +34,7 @@ import org.codehaus.plexus.util.IOUtil; * A very simple artifact packaging mapper, that has everything for quick-start wired in this class. Also, it takes into * account the "${nexus-work}/conf/packaging2extension-mapping.properties" file into account if found. To override the * "defaults" in this class, simply add lines to properties file with same keys. - * + * * @author cstamas */ @Component( role = ArtifactPackagingMapper.class ) @@ -42,11 +42,12 @@ public class DefaultArtifactPackagingMap extends AbstractLogEnabled implements ArtifactPackagingMapper { + public static final String MAPPING_PROPERTIES_FILE = "packaging2extension-mapping.properties"; private File propertiesFile; - private Map<String, String> packaging2extensionMapping; + private volatile Map<String, String> packaging2extensionMapping; private final static Map<String, String> defaults; @@ -75,55 +76,65 @@ public class DefaultArtifactPackagingMap this.packaging2extensionMapping = null; } - public synchronized Map<String, String> getPackaging2extensionMapping() + public Map<String, String> getPackaging2extensionMapping() { if ( packaging2extensionMapping == null ) { - packaging2extensionMapping = new HashMap<String, String>(); + synchronized ( this ) + { + if ( packaging2extensionMapping == null ) + { + packaging2extensionMapping = new HashMap<String, String>(); - // merge defaults - packaging2extensionMapping.putAll( defaults ); + // merge defaults + packaging2extensionMapping.putAll( defaults ); - if ( propertiesFile != null && propertiesFile.exists() ) - { - getLogger().info( "Found user artifact packaging mapping file, applying it..." ); + if ( propertiesFile != null && propertiesFile.exists() ) + { + getLogger().info( "Found user artifact packaging mapping file, applying it..." ); - Properties userMappings = new Properties(); + Properties userMappings = new Properties(); - FileInputStream fis = null; + FileInputStream fis = null; - try - { - fis = new FileInputStream( propertiesFile ); + try + { + fis = new FileInputStream( propertiesFile ); - userMappings.load( fis ); + userMappings.load( fis ); - if ( userMappings.keySet().size() > 0 ) - { - for ( Object key : userMappings.keySet() ) + if ( userMappings.keySet().size() > 0 ) + { + for ( Object key : userMappings.keySet() ) + { + packaging2extensionMapping.put( key.toString(), + userMappings.getProperty( key.toString() ) ); + } + + getLogger().info( + propertiesFile.getAbsolutePath() + + " user artifact packaging mapping file contained " + + userMappings.keySet().size() + " mappings, applied them all succesfully." ); + } + } + catch ( IOException e ) + { + getLogger().warn( + "Got IO exception during read of file: " + propertiesFile.getAbsolutePath() ); + } + finally { - packaging2extensionMapping.put( key.toString(), userMappings.getProperty( key.toString() ) ); + IOUtil.close( fis ); } - getLogger().info( - propertiesFile.getAbsolutePath() + " user artifact packaging mapping file contained " - + userMappings.keySet().size() + " mappings, applied them all succesfully." ); + } + else + { + // make it silent if using defaults + getLogger().debug( + "User artifact packaging mappings file not found, will work with defaults..." ); } } - catch ( IOException e ) - { - getLogger().warn( "Got IO exception during read of file: " + propertiesFile.getAbsolutePath() ); - } - finally - { - IOUtil.close( fis ); - } - - } - else - { - // make it silent if using defaults - getLogger().debug( "User artifact packaging mappings file not found, will work with defaults..." ); } } Modified: maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/VersionUtils.java URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/VersionUtils.java?rev=1210500&r1=1210499&r2=1210500&view=diff ============================================================================== --- maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/VersionUtils.java (original) +++ maven/indexer/trunk/indexer-artifact/src/main/java/org/apache/maven/index/artifact/VersionUtils.java Mon Dec 5 15:36:56 2011 @@ -26,16 +26,15 @@ import java.util.regex.Pattern; */ public class VersionUtils { + private static String SNAPSHOT_VERSION = "SNAPSHOT"; private static final Pattern VERSION_FILE_PATTERN = - Pattern.compile( "^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$|^([0-9]{8}.[0-9]{6})-([0-9]+)$|^(.*)([0-9]{8}.[0-9]{6})-([0-9]+)$" ); + Pattern.compile( + "^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$|^([0-9]{8}.[0-9]{6})-([0-9]+)$|^(.*)([0-9]{8}.[0-9]{6})-([0-9]+)$" ); public static boolean isSnapshot( String version ) { - synchronized ( VERSION_FILE_PATTERN ) - { - return VERSION_FILE_PATTERN.matcher( version ).matches() || version.endsWith( SNAPSHOT_VERSION ); - } + return VERSION_FILE_PATTERN.matcher( version ).matches() || version.endsWith( SNAPSHOT_VERSION ); } }