From 4628a6869c01bfcb697336926fe04c5eab90d287 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 5 Aug 2009 15:34:31 +0000 Subject: [PATCH] 282447 concurrent destinations in HttpClient git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@640 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../org/eclipse/jetty/client/HttpClient.java | 27 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 6785979ab16..de177e3b0ea 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -3,6 +3,7 @@ jetty-7.0.0.RC3-SNAPSHOT + JETTY-1074 JMX thread manipulation + Improved deferred authentication handling + 285697 extract parameters if dispatch has query + + 282447 concurrent destinations in HttpClient jetty-7.0.0.RC2 29 June 2009 + 283844 Webapp / TLD errors are not clear diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index f0b8b62fd08..31eb2a056b8 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -23,6 +23,8 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.KeyManager; @@ -86,7 +88,7 @@ public class HttpClient extends HttpBuffers implements Attributes private int _connectorType = CONNECTOR_SELECT_CHANNEL; private boolean _useDirectBuffers = true; private int _maxConnectionsPerAddress = Integer.MAX_VALUE; - private Map _destinations = new HashMap(); + private ConcurrentMap _destinations = new ConcurrentHashMap(); ThreadPool _threadPool; Connector _connector; private long _idleTimeout = 20000; @@ -222,22 +224,21 @@ public class HttpClient extends HttpBuffers implements Attributes if (remote == null) throw new UnknownHostException("Remote socket address cannot be null."); - synchronized (_destinations) + HttpDestination destination = _destinations.get(remote); + if (destination == null) { - HttpDestination destination = _destinations.get(remote); - if (destination == null) + destination = new HttpDestination(this, remote, ssl, _maxConnectionsPerAddress); + if (_proxy != null && (_noProxy == null || !_noProxy.contains(remote.getHost()))) { - destination = new HttpDestination(this, remote, ssl, _maxConnectionsPerAddress); - if (_proxy != null && (_noProxy == null || !_noProxy.contains(remote.getHost()))) - { - destination.setProxy(_proxy); - if (_proxyAuthentication != null) - destination.setProxyAuthentication(_proxyAuthentication); - } - _destinations.put(remote, destination); + destination.setProxy(_proxy); + if (_proxyAuthentication != null) + destination.setProxyAuthentication(_proxyAuthentication); } - return destination; + HttpDestination other =_destinations.putIfAbsent(remote, destination); + if (other!=null) + destination=other; } + return destination; } /* ------------------------------------------------------------ */