diff options
author | Olivier Lamy <olamy@apache.org> | 2012-01-24 23:42:05 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-01-24 23:42:05 +0000 |
commit | 5eed5ccf55feee3d58bbd5307fd7795cde556f5e (patch) | |
tree | cdccb63869583675351c644c33de25f4ee3900c3 | |
parent | 92e0de2ef148d12420223bd32497fe1d594005db (diff) | |
download | archiva-5eed5ccf55feee3d58bbd5307fd7795cde556f5e.tar.gz archiva-5eed5ccf55feee3d58bbd5307fd7795cde556f5e.zip |
use ConcurrentHashMap rather than synchronized block
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1235558 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java | 153 |
1 files changed, 73 insertions, 80 deletions
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<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<String, List<ProxyConnector>>(); - private Map<String, ProxyInfo> networkProxyMap = new HashMap<String, ProxyInfo>(); + private Map<String, ProxyInfo> networkProxyMap = new ConcurrentHashMap<String, ProxyInfo>(); /** * @@ -168,98 +169,93 @@ public class DefaultRepositoryProxyConnectors @SuppressWarnings( "unchecked" ) private void initConnectorsAndNetworkProxies() { - synchronized ( this.proxyConnectorMap ) + + ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator(); + this.proxyConnectorMap.clear(); + + List<ProxyConnectorConfiguration> proxyConfigs = archivaConfiguration.getConfiguration().getProxyConnectors(); + for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs ) { - ProxyConnectorOrderComparator proxyOrderSorter = new ProxyConnectorOrderComparator(); - this.proxyConnectorMap.clear(); + String key = proxyConfig.getSourceRepoId(); - List<ProxyConnectorConfiguration> 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<String> blacklist = new ArrayList<String>( 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<String> blacklist = new ArrayList<String>( 0 ); - if ( CollectionUtils.isNotEmpty( proxyConfig.getBlackListPatterns() ) ) - { - blacklist.addAll( proxyConfig.getBlackListPatterns() ); - } - connector.setBlacklist( blacklist ); - - // Copy any whitelist patterns. - List<String> whitelist = new ArrayList<String>( 0 ); - if ( CollectionUtils.isNotEmpty( proxyConfig.getWhiteListPatterns() ) ) - { - whitelist.addAll( proxyConfig.getWhiteListPatterns() ); - } - connector.setWhitelist( whitelist ); - - // Get other connectors - List<ProxyConnector> connectors = this.proxyConnectorMap.get( key ); - if ( connectors == null ) - { - // Create if we are the first. - connectors = new ArrayList<ProxyConnector>( 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<String> whitelist = new ArrayList<String>( 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<ProxyConnector> 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<ProxyConnector>( 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<NetworkProxyConfiguration> networkProxies = - archivaConfiguration.getConfiguration().getNetworkProxies(); - for ( NetworkProxyConfiguration networkProxyConfig : networkProxies ) - { - String key = networkProxyConfig.getId(); + List<NetworkProxyConfiguration> 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() ) { |