From: Olivier Lamy Date: Tue, 24 Jan 2012 23:42:05 +0000 (+0000) Subject: use ConcurrentHashMap rather than synchronized block X-Git-Tag: archiva-1.4-M3~1479 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5eed5ccf55feee3d58bbd5307fd7795cde556f5e;p=archiva.git use ConcurrentHashMap rather than synchronized block git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1235558 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java index d6f1604a6..e8be34ea0 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java @@ -79,6 +79,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; /** * DefaultRepositoryProxyConnectors @@ -140,7 +141,7 @@ public class DefaultRepositoryProxyConnectors private Map> proxyConnectorMap = new HashMap>(); - private Map networkProxyMap = new HashMap(); + private Map networkProxyMap = new ConcurrentHashMap(); /** * @@ -168,98 +169,93 @@ public class DefaultRepositoryProxyConnectors @SuppressWarnings( "unchecked" ) private void initConnectorsAndNetworkProxies() { - synchronized ( this.proxyConnectorMap ) + + ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator(); + this.proxyConnectorMap.clear(); + + List proxyConfigs = archivaConfiguration.getConfiguration().getProxyConnectors(); + for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs ) { - ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator(); - this.proxyConnectorMap.clear(); + String key = proxyConfig.getSourceRepoId(); - List proxyConfigs = - archivaConfiguration.getConfiguration().getProxyConnectors(); - for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs ) + try { - String key = proxyConfig.getSourceRepoId(); - - try + // Create connector object. + ProxyConnector connector = new ProxyConnector(); + + connector.setSourceRepository( + repositoryFactory.getManagedRepositoryContent( proxyConfig.getSourceRepoId() ) ); + connector.setTargetRepository( + repositoryFactory.getRemoteRepositoryContent( proxyConfig.getTargetRepoId() ) ); + + connector.setProxyId( proxyConfig.getProxyId() ); + connector.setPolicies( proxyConfig.getPolicies() ); + connector.setOrder( proxyConfig.getOrder() ); + connector.setDisabled( proxyConfig.isDisabled() ); + + // Copy any blacklist patterns. + List blacklist = new ArrayList( 0 ); + if ( CollectionUtils.isNotEmpty( proxyConfig.getBlackListPatterns() ) ) { - // Create connector object. - ProxyConnector connector = new ProxyConnector(); - - connector.setSourceRepository( - repositoryFactory.getManagedRepositoryContent( proxyConfig.getSourceRepoId() ) ); - connector.setTargetRepository( - repositoryFactory.getRemoteRepositoryContent( proxyConfig.getTargetRepoId() ) ); - - connector.setProxyId( proxyConfig.getProxyId() ); - connector.setPolicies( proxyConfig.getPolicies() ); - connector.setOrder( proxyConfig.getOrder() ); - connector.setDisabled( proxyConfig.isDisabled() ); - - // Copy any blacklist patterns. - List blacklist = new ArrayList( 0 ); - if ( CollectionUtils.isNotEmpty( proxyConfig.getBlackListPatterns() ) ) - { - blacklist.addAll( proxyConfig.getBlackListPatterns() ); - } - connector.setBlacklist( blacklist ); - - // Copy any whitelist patterns. - List whitelist = new ArrayList( 0 ); - if ( CollectionUtils.isNotEmpty( proxyConfig.getWhiteListPatterns() ) ) - { - whitelist.addAll( proxyConfig.getWhiteListPatterns() ); - } - connector.setWhitelist( whitelist ); - - // Get other connectors - List connectors = this.proxyConnectorMap.get( key ); - if ( connectors == null ) - { - // Create if we are the first. - connectors = new ArrayList( 1 ); - } - - // Add the connector. - connectors.add( connector ); - - // Ensure the list is sorted. - Collections.sort( connectors, proxyOrderSorter ); - - // Set the key to the list of connectors. - this.proxyConnectorMap.put( key, connectors ); + blacklist.addAll( proxyConfig.getBlackListPatterns() ); } - catch ( RepositoryNotFoundException e ) + connector.setBlacklist( blacklist ); + + // Copy any whitelist patterns. + List whitelist = new ArrayList( 0 ); + if ( CollectionUtils.isNotEmpty( proxyConfig.getWhiteListPatterns() ) ) { - log.warn( "Unable to use proxy connector: " + e.getMessage(), e ); + whitelist.addAll( proxyConfig.getWhiteListPatterns() ); } - catch ( RepositoryException e ) + connector.setWhitelist( whitelist ); + + // Get other connectors + List connectors = this.proxyConnectorMap.get( key ); + if ( connectors == null ) { - log.warn( "Unable to use proxy connector: " + e.getMessage(), e ); + // Create if we are the first. + connectors = new ArrayList( 1 ); } + + // Add the connector. + connectors.add( connector ); + + // Ensure the list is sorted. + Collections.sort( connectors, proxyOrderSorter ); + + // Set the key to the list of connectors. + this.proxyConnectorMap.put( key, connectors ); } + catch ( RepositoryNotFoundException e ) + { + log.warn( "Unable to use proxy connector: " + e.getMessage(), e ); + } + catch ( RepositoryException e ) + { + log.warn( "Unable to use proxy connector: " + e.getMessage(), e ); + } + } - synchronized ( this.networkProxyMap ) - { - this.networkProxyMap.clear(); + this.networkProxyMap.clear(); - List networkProxies = - archivaConfiguration.getConfiguration().getNetworkProxies(); - for ( NetworkProxyConfiguration networkProxyConfig : networkProxies ) - { - String key = networkProxyConfig.getId(); + List networkProxies = archivaConfiguration.getConfiguration().getNetworkProxies(); + for ( NetworkProxyConfiguration networkProxyConfig : networkProxies ) + { + String key = networkProxyConfig.getId(); - ProxyInfo proxy = new ProxyInfo(); + ProxyInfo proxy = new ProxyInfo(); - proxy.setType( networkProxyConfig.getProtocol() ); - proxy.setHost( networkProxyConfig.getHost() ); - proxy.setPort( networkProxyConfig.getPort() ); - proxy.setUserName( networkProxyConfig.getUsername() ); - proxy.setPassword( networkProxyConfig.getPassword() ); + proxy.setType( networkProxyConfig.getProtocol() ); + proxy.setHost( networkProxyConfig.getHost() ); + proxy.setPort( networkProxyConfig.getPort() ); + proxy.setUserName( networkProxyConfig.getUsername() ); + proxy.setPassword( networkProxyConfig.getPassword() ); - this.networkProxyMap.put( key, proxy ); - } + this.networkProxyMap.put( key, proxy ); } + } public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact ) @@ -1046,11 +1042,8 @@ public class DefaultRepositoryProxyConnectors { boolean connected = false; - final ProxyInfo networkProxy; - synchronized ( this.networkProxyMap ) - { - networkProxy = (ProxyInfo) this.networkProxyMap.get( connector.getProxyId() ); - } + final ProxyInfo networkProxy = this.networkProxyMap.get( connector.getProxyId() ); + if ( log.isDebugEnabled() ) {