JETTY-1015 work in progress

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@207 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2009-05-07 06:46:40 +00:00
parent 3ee44fd757
commit ab24a94666
4 changed files with 41 additions and 25 deletions

View File

@ -85,7 +85,7 @@ public class HttpClient extends AbstractBuffers implements Attributes
private int _connectorType = CONNECTOR_SELECT_CHANNEL;
private boolean _useDirectBuffers = true;
private int _maxConnectionsPerAddress = 32;
private int _maxConnectionsPerAddress = Integer.MAX_VALUE;
private Map<Address, HttpDestination> _destinations = new HashMap<Address, HttpDestination>();
ThreadPool _threadPool;
Connector _connector;
@ -121,12 +121,19 @@ public class HttpClient extends AbstractBuffers implements Attributes
private AttributesMap _attributes=new AttributesMap();
/* ------------------------------------------------------------------------------- */
public void dump() throws IOException
public void dump()
{
for (Map.Entry<Address, HttpDestination> entry : _destinations.entrySet())
try
{
System.err.println("\n" + entry.getKey() + ":");
entry.getValue().dump();
for (Map.Entry<Address, HttpDestination> entry : _destinations.entrySet())
{
Log.info("\n" + entry.getKey() + ":");
entry.getValue().dump();
}
}
catch(Exception e)
{
Log.warn(e);
}
}

View File

@ -61,10 +61,10 @@ public class HttpConnection implements Connection
public void dump() throws IOException
{
System.err.println("endp=" + _endp + " " + _endp.isBufferingInput() + " " + _endp.isBufferingOutput());
System.err.println("generator=" + _generator);
System.err.println("parser=" + _parser.getState() + " " + _parser.isMoreInBuffer());
System.err.println("exchange=" + _exchange);
Log.info("endp=" + _endp + " " + _endp.isBufferingInput() + " " + _endp.isBufferingOutput());
Log.info("generator=" + _generator);
Log.info("parser=" + _parser.getState() + " " + _parser.isMoreInBuffer());
Log.info("exchange=" + _exchange);
if (_endp instanceof SslSelectChannelEndPoint)
((SslSelectChannelEndPoint)_endp).dump();
}
@ -296,6 +296,7 @@ public class HttpConnection implements Connection
}
}
failed = true;
Log.warn("IOE on "+_exchange);
throw e;
}
finally

View File

@ -35,13 +35,13 @@ import org.eclipse.jetty.util.log.Log;
*/
public class HttpDestination
{
private ByteArrayBuffer _hostHeader;
private final ByteArrayBuffer _hostHeader;
private final Address _address;
private final LinkedList<HttpConnection> _connections = new LinkedList<HttpConnection>();
private final ArrayList<HttpConnection> _idle = new ArrayList<HttpConnection>();
private final HttpClient _client;
private final boolean _ssl;
private int _maxConnections;
private final int _maxConnections;
private int _pendingConnections = 0;
private ArrayBlockingQueue<Object> _newQueue = new ArrayBlockingQueue<Object>(10, true);
private int _newConnection = 0;
@ -50,14 +50,15 @@ public class HttpDestination
private PathMap _authorizations;
private List<HttpCookie> _cookies;
/* ------------------------------------------------------------ */
public void dump() throws IOException
{
synchronized (this)
{
System.err.println(this);
System.err.println("connections=" + _connections.size());
System.err.println("idle=" + _idle.size());
System.err.println("pending=" + _pendingConnections);
Log.info(this.toString());
Log.info("connections=" + _connections.size());
Log.info("idle=" + _idle.size());
Log.info("pending=" + _pendingConnections);
for (HttpConnection c : _connections)
{
if (!c.isIdle())
@ -70,9 +71,9 @@ public class HttpDestination
private LinkedList<HttpExchange> _queue = new LinkedList<HttpExchange>();
/* ------------------------------------------------------------ */
HttpDestination(HttpClient pool, Address address, boolean ssl, int maxConnections)
HttpDestination(HttpClient client, Address address, boolean ssl, int maxConnections)
{
_client = pool;
_client = client;
_address = address;
_ssl = ssl;
_maxConnections = maxConnections;
@ -211,6 +212,12 @@ public class HttpDestination
{
synchronized (this)
{
if (connection!=null)
{
_connections.remove(connection);
connection.getEndPoint().close();
connection=null;
}
if (_idle.size() > 0)
connection = _idle.remove(_idle.size()-1);
}
@ -222,9 +229,6 @@ public class HttpDestination
if (connection.getEndPoint().isOpen() && (last==0 || ((now-last)<idleTimeout)) )
return connection;
_connections.remove(connection);
connection.getEndPoint().close();
connection=null;
}
}
@ -455,12 +459,16 @@ public class HttpDestination
((Authorization)auth).setCredentials(ex);
}
synchronized (this)
HttpConnection connection = getIdleConnection();
if (connection != null)
{
//System.out.println( "Sending: " + ex.toString() );
boolean sent = connection.send(ex);
if (!sent) connection = null;
}
HttpConnection connection = null;
if (_queue.size() > 0 || (connection = getIdleConnection()) == null || !connection.send(ex))
if (connection == null)
{
synchronized (this)
{
_queue.add(ex);
if (_connections.size() + _pendingConnections < _maxConnections)

View File

@ -97,7 +97,7 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
// TODO get rid of these dumps
public void dump()
{
System.err.println(_result);
Log.info(""+_result);
// System.err.println(h.toString());
// System.err.println("--");
}