mirror of https://github.com/apache/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
This commit is contained in:
parent
92e0de2ef1
commit
5eed5ccf55
|
@ -79,6 +79,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DefaultRepositoryProxyConnectors
|
* DefaultRepositoryProxyConnectors
|
||||||
|
@ -140,7 +141,7 @@ public class DefaultRepositoryProxyConnectors
|
||||||
|
|
||||||
private Map<String, List<ProxyConnector>> proxyConnectorMap = new HashMap<String, List<ProxyConnector>>();
|
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" )
|
@SuppressWarnings( "unchecked" )
|
||||||
private void initConnectorsAndNetworkProxies()
|
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();
|
String key = proxyConfig.getSourceRepoId();
|
||||||
this.proxyConnectorMap.clear();
|
|
||||||
|
|
||||||
List<ProxyConnectorConfiguration> proxyConfigs =
|
try
|
||||||
archivaConfiguration.getConfiguration().getProxyConnectors();
|
|
||||||
for ( ProxyConnectorConfiguration proxyConfig : proxyConfigs )
|
|
||||||
{
|
{
|
||||||
String key = proxyConfig.getSourceRepoId();
|
// Create connector object.
|
||||||
|
ProxyConnector connector = new ProxyConnector();
|
||||||
|
|
||||||
try
|
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.
|
blacklist.addAll( proxyConfig.getBlackListPatterns() );
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
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();
|
||||||
|
|
||||||
|
List<NetworkProxyConfiguration> networkProxies = archivaConfiguration.getConfiguration().getNetworkProxies();
|
||||||
|
for ( NetworkProxyConfiguration networkProxyConfig : networkProxies )
|
||||||
{
|
{
|
||||||
this.networkProxyMap.clear();
|
String key = networkProxyConfig.getId();
|
||||||
|
|
||||||
List<NetworkProxyConfiguration> networkProxies =
|
ProxyInfo proxy = new ProxyInfo();
|
||||||
archivaConfiguration.getConfiguration().getNetworkProxies();
|
|
||||||
for ( NetworkProxyConfiguration networkProxyConfig : networkProxies )
|
|
||||||
{
|
|
||||||
String key = networkProxyConfig.getId();
|
|
||||||
|
|
||||||
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() );
|
this.networkProxyMap.put( key, proxy );
|
||||||
proxy.setHost( networkProxyConfig.getHost() );
|
|
||||||
proxy.setPort( networkProxyConfig.getPort() );
|
|
||||||
proxy.setUserName( networkProxyConfig.getUsername() );
|
|
||||||
proxy.setPassword( networkProxyConfig.getPassword() );
|
|
||||||
|
|
||||||
this.networkProxyMap.put( key, proxy );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
|
public File fetchFromProxies( ManagedRepositoryContent repository, ArtifactReference artifact )
|
||||||
|
@ -1046,11 +1042,8 @@ public class DefaultRepositoryProxyConnectors
|
||||||
{
|
{
|
||||||
boolean connected = false;
|
boolean connected = false;
|
||||||
|
|
||||||
final ProxyInfo networkProxy;
|
final ProxyInfo networkProxy = this.networkProxyMap.get( connector.getProxyId() );
|
||||||
synchronized ( this.networkProxyMap )
|
|
||||||
{
|
|
||||||
networkProxy = (ProxyInfo) this.networkProxyMap.get( connector.getProxyId() );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( log.isDebugEnabled() )
|
if ( log.isDebugEnabled() )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue