3909N/A * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A class that implements a cache of idle Http connections for keep-alive 0N/A * @author Stephen R. Pietrowicz (NCSA) 0N/A * @author Dave Brown 0N/A /* maximum # keep-alive connections to maintain at once 0N/A * This should be 2 by the HTTP spec, but because we don't support pipe-lining 0N/A * a larger value is more appropriate. So we now set a default of 5, and the value 0N/A * refers to the number of idle connections per destination (in the cache) only. 0N/A * It can be reset by setting system property "http.maxConnections". 0N/A * Register this URL and HttpClient (that supports keep-alive) with the cache 0N/A * @param url The URL contains info about the host and port 0N/A * @param http The HttpClient to be cached 0N/A /* Unfortunately, we can't always believe the keep-alive timeout we got 0N/A * back from the server. If I'm connected through a Netscape proxy 0N/A * to a server that sent me a keep-alive 0N/A * time of 15 sec, the proxy unilaterally terminates my connection 28N/A * The robustness to get around this is in HttpClient.parseHTTP() 0N/A // We want to create the Keep-Alive-Timer in the 0N/A // system threadgroup 3480N/A // Set the context class loader to null in order to avoid 3480N/A // keeping a strong reference to an application classloader. 28N/A /* remove an obsolete HttpClient from its VectorCache */ 28N/A /* called by a clientVector thread when all its connections have timed out 0N/A * and that vector of connections should be removed. 0N/A * Check to see if this URL has a cached HttpClient 0N/A if (v ==
null) {
// nothing in cache yet 0N/A /* Sleeps for an alloted timeout, then checks for timed out connections. 0N/A * Errs on the side of caution (leave connections idle for a relatively 0N/A synchronized (
this) {
0N/A /* Remove all unused HttpClients. Starting from the 0N/A * bottom of the stack (the least-recently used first). 0N/A * REMIND: It'd be nice to not remove *all* connections 0N/A * that aren't presently in use. One could have been added 0N/A * a second ago that's still perfectly valid, and we're 0N/A * needlessly axing it. But it's not clear how to do this 0N/A * cleanly, and doing it right may be more trouble than it's 0N/A * Do not serialize this class! 0N/A/* FILO order for recycling HttpClients, should run in a thread 0N/A * to time them out. If > maxConns are in use, block. 0N/A // sleep time in milliseconds, before cache clear 0N/A // Loop until we find a connection that has not timed out 0N/A /* return a still valid, unused HttpClient */ 0N/A * Do not serialize this class! 0N/A * @param url the URL containing the protocol, host and port information 0N/A * Determine whether or not two objects of this type are equal 0N/A * The hashCode() for this object is the string hashCode() of 0N/A * concatenation of the protocol, host name and port.