httpclient-4.3.5

teComplete();
    }
  }
  
  public void shutdown()
  {
    if (isShutDown.compareAndSet(false, true))
    {
      log.debug("Connection manager is shutting down");
      try
      {
        pool.shutdown();
      }
      catch (IOException ex)
      {
        log.debug("I/O exception shutting down connection manager", ex);
      }
      log.debug("Connection manager shut down");
    }
  }
  
  public void closeIdleConnections(long idleTimeout, TimeUnit tunit)
  {
    if (log.isDebugEnabled()) {
      log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
    }
    pool.closeIdle(idleTimeout, tunit);
  }
  
  public void closeExpiredConnections()
  {
    log.debug("Closing expired connections");
    pool.closeExpired();
  }
  
  public int getMaxTotal()
  {
    return pool.getMaxTotal();
  }
  
  public void setMaxTotal(int max)
  {
    pool.setMaxTotal(max);
  }
  
  public int getDefaultMaxPerRoute()
  {
    return pool.getDefaultMaxPerRoute();
  }
  
  public void setDefaultMaxPerRoute(int max)
  {
    pool.setDefaultMaxPerRoute(max);
  }
  
  public int getMaxPerRoute(HttpRoute route)
  {
    return pool.getMaxPerRoute(route);
  }
  
  public void setMaxPerRoute(HttpRoute route, int max)
  {
    pool.setMaxPerRoute(route, max);
  }
  
  public PoolStats getTotalStats()
  {
    return pool.getTotalStats();
  }
  
  public PoolStats getStats(HttpRoute route)
  {
    return pool.getStats(route);
  }
  
  public SocketConfig getDefaultSocketConfig()
  {
    return configData.getDefaultSocketConfig();
  }
  
  public void setDefaultSocketConfig(SocketConfig defaultSocketConfig)
  {
    configData.setDefaultSocketConfig(defaultSocketConfig);
  }
  
  public ConnectionConfig getDefaultConnectionConfig()
  {
    return configData.getDefaultConnectionConfig();
  }
  
  public void setDefaultConnectionConfig(ConnectionConfig defaultConnectionConfig)
  {
    configData.setDefaultConnectionConfig(defaultConnectionConfig);
  }
  
  public SocketConfig getSocketConfig(HttpHost host)
  {
    return configData.getSocketConfig(host);
  }
  
  public void setSocketConfig(HttpHost host, SocketConfig socketConfig)
  {
    configData.setSocketConfig(host, socketConfig);
  }
  
  public ConnectionConfig getConnectionConfig(HttpHost host)
  {
    return configData.getConnectionConfig(host);
  }
  
  public void setConnectionConfig(HttpHost host, ConnectionConfig connectionConfig)
  {
    configData.setConnectionConfig(host, connectionConfig);
  }
  
  static class ConfigData
  {
    private final Map<HttpHost, SocketConfig> socketConfigMap;
    private final Map<HttpHost, ConnectionConfig> connectionConfigMap;
    private volatile SocketConfig defaultSocketConfig;
    private volatile ConnectionConfig defaultConnectionConfig;
    
    ConfigData()
    {
      socketConfigMap = new ConcurrentHashMap();
      connectionConfigMap = new ConcurrentHashMap();
    }
    
    public SocketConfig getDefaultSocketConfig()
    {
      return defaultSocketConfig;
    }
    
    public void setDefaultSocketConfig(SocketConfig defaultSocketConfig)
    {
      this.defaultSocketConfig = defaultSocketConfig;
    }
    
    public ConnectionConfig getDefaultConnectionConfig()
    {
      return defaultConnectionConfig;
    }
    
    public void setDefaultConnectionConfig(ConnectionConfig defaultConnectionConfig)
    {
      this.defaultConnectionConfig = defaultConnectionConfig;
    }
    
    public SocketConfig getSocketConfig(HttpHost host)
    {
      return (SocketConfig)socketConfigMap.get(host);
    }
    
    public void setSocketConfig(HttpHost host, SocketConfig socketConfig)
    {
      socketConfigMap.put(host, socketConfig);
    }
    
    public ConnectionConfig getConnectionConfig(HttpHost host)
    {
      return (ConnectionConfig)connectionConfigMap.get(host);
    }
    
    public void setConnectionConfig(HttpHost host, ConnectionConfig connectionConfig)
    {
      connectionConfigMap.put(host, connectionConfig);
    }
  }
  
  static class InternalConnectionFactory
    implements ConnFactory<HttpRoute, ManagedHttpClientConnection>
  {
    private final PoolingHttpClientConnectionManager.ConfigData configData;
    private final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory;
    
    InternalConnectionFactory(PoolingHttpClientConnectionManager.ConfigData configData, HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory)
    {
      this.configData = (configData != null ? configData : new PoolingHttpClientConnectionManager.ConfigData());
      this.connFactory = (connFactory != null ? connFactory : ManagedHttpClientConnectionFactory.INSTANCE);
    }
    
    public ManagedHttpClientConnection create(HttpRoute route)
      throws IOException
    {
      ConnectionConfig config = null;
      if (route.getProxyHost() != null) {
        config = configData.getConnectionConfig(route.getProxyHost());
      }
      if (config == null) {
        config = configData.getConnectionConfig(route.getTargetHost());
      }
      if (config == null) {
        config = configData.getDefaultConnectionConfig();
      }
      if (config == null) {
        config = ConnectionConfig.DEFAULT;
      }
      return (ManagedHttpClientConnection)connFactory.create(route, config);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.PoolingHttpClientConnectionManager
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.conn.DnsResolver;
import org.apache.http.util.Args;

public class InMemoryDnsResolver
  implements DnsResolver
{
  private final Log log = LogFactory.getLog(InMemoryDnsResolver.class);
  private final Map<String, InetAddress[]> dnsMap;
  
  public InMemoryDnsResolver()
  {
    dnsMap = new ConcurrentHashMap();
  }
  
  public void add(String host, InetAddress... ips)
  {
    Args.notNull(host, "Host name");
    Args.notNull(ips, "Array of IP addresses");
    dnsMap.put(host, ips);
  }
  
  public InetAddress[] resolve(String host)
    throws UnknownHostException
  {
    InetAddress[] resolvedAddresses = (InetAddress[])dnsMap.get(host);
    if (log.isInfoEnabled()) {
      log.info("Resolving " + host + " to " + Arrays.deepToString(resolvedAddresses));
    }
    if (resolvedAddresses == null) {
      throw new UnknownHostException(host + " cannot be resolved");
    }
    return resolvedAddresses;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.InMemoryDnsResolver
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import javax.net.ssl.SSLSession;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpConnectionMetrics;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.conn.ManagedHttpClientConnection;
import org.apache.http.protocol.HttpContext;

@NotThreadSafe
class CPoolProxy
  implements ManagedHttpClientConnection, HttpContext
{
  private volatile CPoolEntry poolEntry;
  
  CPoolProxy(CPoolEntry entry)
  {
    poolEntry = entry;
  }
  
  CPoolEntry getPoolEntry()
  {
    return poolEntry;
  }
  
  CPoolEntry detach()
  {
    CPoolEntry local = poolEntry;
    poolEntry = null;
    return local;
  }
  
  ManagedHttpClientConnection getConnection()
  {
    CPoolEntry local = poolEntry;
    if (local == null) {
      return null;
    }
    return (ManagedHttpClientConnection)local.getConnection();
  }
  
  ManagedHttpClientConnection getValidConnection()
  {
    ManagedHttpClientConnection conn = getConnection();
    if (conn == null) {
      throw new ConnectionShutdownException();
    }
    return conn;
  }
  
  public void close()
    throws IOException
  {
    CPoolEntry local = poolEntry;
    if (local != null) {
      local.closeConnection();
    }
  }
  
  public void shutdown()
    throws IOException
  {
    CPoolEntry local = poolEntry;
    if (local != null) {
      local.shutdownConnection();
    }
  }
  
  public boolean isOpen()
  {
    CPoolEntry local = poolEntry;
    if (local != null) {
      return !local.isClosed();
    }
    return false;
  }
  
  public boolean isStale()
  {
    HttpClientConnection conn = getConnection();
    if (conn != null) {
      return conn.isStale();
    }
    return true;
  }
  
  public void setSocketTimeout(int timeout)
  {
    getValidConnection().setSocketTimeout(timeout);
  }
  
  public int getSocketTimeout()
  {
    return getValidConnection().getSocketTimeout();
  }
  
  public String getId()
  {
    return getValidConnection().getId();
  }
  
  public void bind(Socket socket)
    throws IOException
  {
    getValidConnection().bind(socket);
  }
  
  public Socket getSocket()
  {
    return getValidConnection().getSocket();
  }
  
  public SSLSession getSSLSession()
  {
    return getValidConnection().getSSLSession();
  }
  
  public boolean isResponseAvailable(int timeout)
    throws IOException
  {
    return getValidConnection().isResponseAvailable(timeout);
  }
  
  public void sendRequestHeader(HttpRequest request)
    throws HttpException, IOException
  {
    getValidConnection().sendRequestHeader(request);
  }
  
  public void sendRequestEntity(HttpEntityEnclosingRequest request)
    throws HttpException, IOException
  {
    getValidConnection().sendRequestEntity(request);
  }
  
  public HttpResponse receiveResponseHeader()
    throws HttpException, IOException
  {
    return getValidConnection().receiveResponseHeader();
  }
  
  public void receiveResponseEntity(HttpResponse response)
    throws HttpException, IOException
  {
    getValidConnection().receiveResponseEntity(response);
  }
  
  public void flush()
    throws IOException
  {
    getValidConnection().flush();
  }
  
  public HttpConnectionMetrics getMetrics()
  {
    return getValidConnection().getMetrics();
  }
  
  public InetAddress getLocalAddress()
  {
    return getValidConnection().getLocalAddress();
  }
  
  public int getLocalPort()
  {
    return getValidConnection().getLocalPort();
  }
  
  public InetAddress getRemoteAddress()
  {
    return getValidConnection().getRemoteAddress();
  }
  
  public int getRemotePort()
  {
    return getValidConnection().getRemotePort();
  }
  
  public Object getAttribute(String id)
  {
    ManagedHttpClientConnection conn = getValidConnection();
    if ((conn instanceof HttpContext)) {
      return ((HttpContext)conn).getAttribute(id);
    }
    return null;
  }
  
  public void setAttribute(String id, Object obj)
  {
    ManagedHttpClientConnection conn = getValidConnection();
    if ((conn instanceof HttpContext)) {
      ((HttpContext)conn).setAttribute(id, obj);
    }
  }
  
  public Object removeAttribute(String id)
  {
    ManagedHttpClientConnection conn = getValidConnection();
    if ((conn instanceof HttpContext)) {
      return ((HttpContext)conn).removeAttribute(id);
    }
    return null;
  }
  
  public String toString()
  {
    StringBuilder sb = new StringBuilder("CPoolProxy{");
    ManagedHttpClientConnection conn = getConnection();
    if (conn != null) {
      sb.append(conn);
    } else {
      sb.append("detached");
    }
    sb.append('}');
    return sb.toString();
  }
  
  public static HttpClientConnection newProxy(CPoolEntry poolEntry)
  {
    return new CPoolProxy(poolEntry);
  }
  
  private static CPoolProxy getProxy(HttpClientConnection conn)
  {
    if (!CPoolProxy.class.isInstance(conn)) {
      throw new IllegalStateException("Unexpected connection proxy class: " + conn.getClass());
    }
    return (CPoolProxy)CPoolProxy.class.cast(conn);
  }
  
  public static CPoolEntry getPoolEntry(HttpClientConnection proxy)
  {
    CPoolEntry entry = getProxy(proxy).getPoolEntry();
    if (entry == null) {
      throw new ConnectionShutdownException();
    }
    return entry;
  }
  
  public static CPoolEntry detach(HttpClientConnection conn)
  {
    return getProxy(conn).detach();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.CPoolProxy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn;

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.ManagedClientConnection;

class PoolingClientConnectionManager$1
  implements ClientConnectionRequest
{
  PoolingClientConnectionManager$1(PoolingClientConnectionManager paramPoolingClientConnectionManager, Future paramFuture) {}
  
  public void abortRequest()
  {
    val$future.cancel(true);
  }
  
  public ManagedClientConnection getConnection(long timeout, TimeUnit tunit)
    throws InterruptedException, ConnectionPoolTimeoutException
  {
    return this$0.leaseConnection(val$future, timeout, tunit);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.PoolingClientConnectionManager.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn;

import java.io.IOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpHost;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Lookup;
import org.apache.http.config.SocketConfig;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.DnsResolver;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.conn.ManagedHttpClientConnection;
import org.apache.http.conn.SchemePortResolver;
import org.apache.http.conn.UnsupportedSchemeException;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.Args;

@Immutable
class HttpClientConnectionOperator
{
  static final String SOCKET_FACTORY_REGISTRY = "http.socket-factory-registry";
  private final Log log = LogFactory.getLog(getClass());
  private final Lookup<ConnectionSocketFactory> socketFactoryRegistry;
  private final SchemePortResolver schemePortResolver;
  private final DnsResolver dnsResolver;
  
  HttpClientConnectionOperator(Lookup<ConnectionSocketFactory> socketFactoryRegistry, SchemePortResolver schemePortResolver, DnsResolver dnsResolver)
  {
    Args.notNull(socketFactoryRegistry, "Socket factory registry");
    this.socketFactoryRegistry = socketFactoryRegistry;
    this.schemePortResolver = (schemePortResolver != null ? schemePortResolver : DefaultSchemePortResolver.INSTANCE);
    
    this.dnsResolver = (dnsResolver != null ? dnsResolver : SystemDefaultDnsResolver.INSTANCE);
  }
  
  private Lookup<ConnectionSocketFactory> getSocketFactoryRegistry(HttpContext context)
  {
    Lookup<ConnectionSocketFactory> reg = (Lookup)context.getAttribute("http.socket-factory-registry");
    if (reg == null) {
      reg = socketFactoryRegistry;
    }
    return reg;
  }
  
  public void connect(ManagedHttpClientConnection conn, HttpHost host, InetSocketAddress localAddress, int connectTimeout, SocketConfig socketConfig, HttpContext context)
    throws IOException
  {
    Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(context);
    ConnectionSocketFactory sf = (ConnectionSocketFactory)registry.lookup(host.getSchemeName());
    if (sf == null) {
      throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }
    InetAddress[] addresses = dnsResolver.resolve(host.getHostName());
    int port = schemePortResolver.resolve(host);
    for (int i = 0; i < addresses.length; i++)
    {
      InetAddress address = addresses[i];
      boolean last = i == addresses.length - 1;
      
      Socket sock = sf.createSocket(context);
      sock.setSoTimeout(socketConfig.getSoTimeout());
      sock.setReuseAddress(socketConfig.isSoReuseAddress());
      sock.setTcpNoDelay(socketConfig.isTcpNoDelay());
      sock.setKeepAlive(socketConfig.isSoKeepAlive());
      int linger = socketConfig.getSoLinger();
      if (linger >= 0) {
        sock.setSoLinger(linger > 0, linger);
      }
      conn.bind(sock);
      
      InetSocketAddress remoteAddress = new InetSocketAddress(address, port);
      if (log.isDebugEnabled()) {
        log.debug("Connecting to " + remoteAddress);
      }
      try
      {
        sock = sf.connectSocket(connectTimeout, sock, host, remoteAddress, localAddress, context);
        
        conn.bind(sock);
        if (log.isDebugEnabled()) {
          log.debug("Connection established " + conn);
        }
        return;
      }
      catch (SocketTimeoutException ex)
      {
        if (last) {
          throw new ConnectTimeoutException(ex, host, addresses);
        }
      }
      catch (ConnectException ex)
      {
        if (last)
        {
          String msg = ex.getMessage();
          if ("Connection timed out".equals(msg)) {
            throw new ConnectTimeoutException(ex, host, addresses);
          }
          throw new HttpHostConnectException(ex, host, addresses);
        }
      }
      if (log.isDebugEnabled()) {
        log.debug("Connect to " + remoteAddress + " timed out. " + "Connection will be retried using another IP address");
      }
    }
  }
  
  public void upgrade(ManagedHttpClientConnection conn, HttpHost host, HttpContext context)
    throws IOException
  {
    HttpClientContext clientContext = HttpClientContext.adapt(context);
    Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext);
    ConnectionSocketFactory sf = (ConnectionSocketFactory)registry.lookup(host.getSchemeName());
    if (sf == null) {
      throw new UnsupportedSchemeException(host.getSchemeName() + " protocol is not supported");
    }
    if (!(sf instanceof LayeredConnectionSocketFactory)) {
      throw new UnsupportedSchemeException(host.getSchemeName() + " protocol does not support connection upgrade");
    }
    LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory)sf;
    Socket sock = conn.getSocket();
    int port = schemePortResolver.resolve(host);
    sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
    conn.bind(sock);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.HttpClientConnectionOperator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn;

import java.io.IOException;
import java.io.InputStream;
import org.apache.http.annotation.NotThreadSafe;

@NotThreadSafe
class LoggingInputStream
  extends InputStream
{
  private final InputStream in;
  private final Wire wire;
  
  public LoggingInputStream(InputStream in, Wire wire)
  {
    this.in = in;
    this.wire = wire;
  }
  
  public int read()
    throws IOException
  {
    try
    {
      int b = in.read();
      if (b == -1) {
        wire.input("end of stream");
      } else {
        wire.input(b);
      }
      return b;
    }
    catch (IOException ex)
    {
      wire.input("[read] I/O error: " + ex.getMessage());
      throw ex;
    }
  }
  
  public int read(byte[] b)
    throws IOException
  {
    try
    {
      int bytesRead = in.read(b);
      if (bytesRead == -1) {
        wire.input("end of stream");
      } else if (bytesRead > 0) {
        wire.input(b, 0, bytesRead);
      }
      return bytesRead;
    }
    catch (IOException ex)
    {
      wire.input("[read] I/O error: " + ex.getMessage());
      throw ex;
    }
  }
  
  public int read(byte[] b, int off, int len)
    throws IOException
  {
    try
    {
      int bytesRead = in.read(b, off, len);
      if (bytesRead == -1) {
        wire.input("end of stream");
      } else if (bytesRead > 0) {
        wire.input(b, off, bytesRead);
      }
      return bytesRead;
    }
    catch (IOException ex)
    {
      wire.input("[read] I/O error: " + ex.getMessage());
      throw ex;
    }
  }
  
  public long skip(long n)
    throws IOException
  {
    try
    {
      return super.skip(n);
    }
    catch (IOException ex)
    {
      wire.input("[skip] I/O error: " + ex.getMessage());
      throw ex;
    }
  }
  
  public int available()
    throws IOException
  {
    try
    {
      return in.available();
    }
    catch (IOException ex)
    {
      wire.input("[available] I/O error : " + ex.getMessage());
      throw ex;
    }
  }
  
  public void mark(int readlimit)
  {
    super.mark(readlimit);
  }
  
  public void reset()
    throws IOException
  {
    super.reset();
  }
  
  public boolean markSupported()
  {
    return false;
  }
  
  public void close()
    throws IOException
  {
    try
    {
      in.close();
    }
    catch (IOException ex)
    {
      wire.input("[close] I/O error: " + ex.getMessage());
      throw ex;
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.LoggingInputStream
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.http.HttpHost;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.config.SocketConfig;

class PoolingHttpClientConnectionManager$ConfigData
{
  private final Map<HttpHost, SocketConfig> socketConfigMap;
  private final Map<HttpHost, ConnectionConfig> connectionConfigMap;
  private volatile SocketConfig defaultSocketConfig;
  private volatile ConnectionConfig defaultConnectionConfig;
  
  PoolingHttpClientConnectionManager$ConfigData()
  {
    socketConfigMap = new ConcurrentHashMap();
    connectionConfigMap = new ConcurrentHashMap();
  }
  
  public SocketConfig getDefaultSocketConfig()
  {
    return defaultSocketConfig;
  }
  
  public void setDefaultSocketConfig(SocketConfig defaultSocketConfig)
  {
    this.defaultSocketConfig = defaultSocketConfig;
  }
  
  public ConnectionConfig getDefaultConnectionConfig()
  {
    return defaultConnectionConfig;
  }
  
  public void setDefaultConnectionConfig(ConnectionConfig defaultConnectionConfig)
  {
    this.defaultConnectionConfig = defaultConnectionConfig;
  }
  
  public SocketConfig getSocketConfig(HttpHost host)
  {
    return (SocketConfig)socketConfigMap.get(host);
  }
  
  public void setSocketConfig(HttpHost host, SocketConfig socketConfig)
  {
    socketConfigMap.put(host, socketConfig);
  }
  
  public ConnectionConfig getConnectionConfig(HttpHost host)
  {
    return (ConnectionConfig)connectionConfigMap.get(host);
  }
  
  public void setConnectionConfig(HttpHost host, ConnectionConfig connectionConfig)
  {
    connectionConfigMap.put(host, connectionConfig);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.PoolingHttpClientConnectionManager.ConfigData
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn.tsccm;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.ClientConnectionRequest;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.conn.params.ConnPerRouteBean;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.conn.DefaultClientConnectionOperator;
import org.apache.http.impl.conn.SchemeRegistryFactory;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;

@Deprecated
@ThreadSafe
public class ThreadSafeClientConnManager
  implements ClientConnectionManager
{
  private final Log log;
  protected final SchemeRegistry schemeRegistry;
  protected final AbstractConnPool connectionPool;
  protected final ConnPoolByRoute pool;
  protected final ClientConnectionOperator connOperator;
  protected final ConnPerRouteBean connPerRoute;
  
  public ThreadSafeClientConnManager(SchemeRegistry schreg)
  {
    this(schreg, -1L, TimeUnit.MILLISECONDS);
  }
  
  public ThreadSafeClientConnManager()
  {
    this(SchemeRegistryFactory.createDefault());
  }
  
  public ThreadSafeClientConnManager(SchemeRegistry schreg, long connTTL, TimeUnit connTTLTimeUnit)
  {
    this(schreg, connTTL, connTTLTimeUnit, new ConnPerRouteBean());
  }
  
  public ThreadSafeClientConnManager(SchemeRegistry schreg, long connTTL, TimeUnit connTTLTimeUnit, ConnPerRouteBean connPerRoute)
  {
    Args.notNull(schreg, "Scheme registry");
    log = LogFactory.getLog(getClass());
    schemeRegistry = schreg;
    this.connPerRoute = connPerRoute;
    connOperator = createConnectionOperator(schreg);
    pool = createConnectionPool(connTTL, connTTLTimeUnit);
    connectionPool = pool;
  }
  
  @Deprecated
  public ThreadSafeClientConnManager(HttpParams params, SchemeRegistry schreg)
  {
    Args.notNull(schreg, "Scheme registry");
    log = LogFactory.getLog(getClass());
    schemeRegistry = schreg;
    connPerRoute = new ConnPerRouteBean();
    connOperator = createConnectionOperator(schreg);
    pool = ((ConnPoolByRoute)createConnectionPool(params));
    connectionPool = pool;
  }
  
  protected void finalize()
    throws Throwable
  {
    try
    {
      shutdown();
    }
    finally
    {
      super.finalize();
    }
  }
  
  @Deprecated
  protected AbstractConnPool createConnectionPool(HttpParams params)
  {
    return new ConnPoolByRoute(connOperator, params);
  }
  
  protected ConnPoolByRoute createConnectionPool(long connTTL, TimeUnit connTTLTimeUnit)
  {
    return new ConnPoolByRoute(connOperator, connPerRoute, 20, connTTL, connTTLTimeUnit);
  }
  
  protected ClientConnectionOperator createConnectionOperator(SchemeRegistry schreg)
  {
    return new DefaultClientConnectionOperator(schreg);
  }
  
  public SchemeRegistry getSchemeRegistry()
  {
    return schemeRegistry;
  }
  
  public ClientConnectionRequest requestConnection(final HttpRoute route, Object state)
  {
    final PoolEntryRequest poolRequest = pool.requestPoolEntry(route, state);
    
    new ClientConnectionRequest()
    {
      public void abortRequest()
      {
        poolRequest.abortRequest();
      }
      
      public ManagedClientConnection getConnection(long timeout, TimeUnit tunit)
        throws InterruptedException, ConnectionPoolTimeoutException
      {
        Args.notNull(route, "Route");
        if (log.isDebugEnabled()) {
          log.debug("Get connection: " + route + ", timeout = " + timeout);
        }
        BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit);
        return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry);
      }
    };
  }
  
  public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit)
  {
    Args.check(conn instanceof BasicPooledConnAdapter, "Connection class mismatch, connection not obtained from this manager");
    
    BasicPooledConnAdapter hca = (BasicPooledConnAdapter)conn;
    if (hca.getPoolEntry() != null) {
      Asserts.check(hca.getManager() == this, "Connection not obtained from this manager");
    }
    synchronized (hca)
    {
      BasicPoolEntry entry = (BasicPoolEntry)hca.getPoolEntry();
      if (entry == null) {
        return;
      }
      try
      {
        if ((hca.isOpen()) && (!hca.isMarkedReusable())) {
          hca.shutdown();
        }
      }
      catch (IOException iox)
      {
        boolean reusable;
        if (log.isDebugEnabled()) {
          log.debug("Exception shutting down released connection.", iox);
        }
      }
      finally
      {
        boolean reusable;
        boolean reusable = hca.isMarkedReusable();
        if (log.isDebugEnabled()) {
          if (reusable) {
            log.debug("Released connection is reusable.");
          } else {
            log.debug("Released connection is not reusable.");
          }
        }
        hca.detach();
        pool.freeEntry(entry, reusable, validDuration, timeUnit);
      }
    }
  }
  
  public void shutdown()
  {
    log.debug("Shutting down");
    pool.shutdown();
  }
  
  public int getConnectionsInPool(HttpRoute route)
  {
    return pool.getConnectionsInPool(route);
  }
  
  public int getConnectionsInPool()
  {
    return pool.getConnectionsInPool();
  }
  
  public void closeIdleConnections(long idleTimeout, TimeUnit tunit)
  {
    if (log.isDebugEnabled()) {
      log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
    }
    pool.closeIdleConnections(idleTimeout, tunit);
  }
  
  public void closeExpiredConnections()
  {
    log.debug("Closing expired connections");
    pool.closeExpiredConnections();
  }
  
  public int getMaxTotal()
  {
    return pool.getMaxTotalConnections();
  }
  
  public void setMaxTotal(int max)
  {
    pool.setMaxTotalConnections(max);
  }
  
  public int getDefaultMaxPerRoute()
  {
    return connPerRoute.getDefaultMaxPerRoute();
  }
  
  public void setDefaultMaxPerRoute(int max)
  {
    connPerRoute.setDefaultMaxPerRoute(max);
  }
  
  public int getMaxForRoute(HttpRoute route)
  {
    return connPerRoute.getMaxForRoute(route);
  }
  
  public void setMaxForRoute(HttpRoute route, int max)
  {
    connPerRoute.setMaxForRoute(route, max);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn.tsccm;

import java.lang.ref.ReferenceQueue;
import java.util.concurrent.TimeUnit;
import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.conn.AbstractPoolEntry;
import org.apache.http.util.Args;

@Deprecated
public class BasicPoolEntry
  extends AbstractPoolEntry
{
  private final long created;
  private long updated;
  private final long validUntil;
  private long expiry;
  
  public BasicPoolEntry(ClientConnectionOperator op, HttpRoute route, ReferenceQueue<Object> queue)
  {
    super(op, route);
    Args.notNull(route, "HTTP route");
    created = System.currentTimeMillis();
    validUntil = Long.MAX_VALUE;
    expiry = validUntil;
  }
  
  public BasicPoolEntry(ClientConnectionOperator op, HttpRoute route)
  {
    this(op, route, -1L, TimeUnit.MILLISECONDS);
  }
  
  public BasicPoolEntry(ClientConnectionOperator op, HttpRoute route, long connTTL, TimeUnit timeunit)
  {
    super(op, route);
    Args.notNull(route, "HTTP route");
    created = System.currentTimeMillis();
    if (connTTL > 0L) {
      validUntil = (created + timeunit.toMillis(connTTL));
    } else {
      validUntil = Long.MAX_VALUE;
    }
    expiry = validUntil;
  }
  
  protected final OperatedClientConnection getConnection()
  {
    return connection;
  }
  
  protected final HttpRoute getPlannedRoute()
  {
    return route;
  }
  
  protected final BasicPoolEntryRef getWeakRef()
  {
    return null;
  }
  
  protected void shutdownEntry()
  {
    super.shutdownEntry();
  }
  
  public long getCreated()
  {
    return created;
  }
  
  public long getUpdated()
  {
    return updated;
  }
  
  public long getExpiry()
  {
    return expiry;
  }
  
  public long getValidUntil()
  {
    return validUntil;
  }
  
  public void updateExpiry(long time, TimeUnit timeunit)
  {
    updated = System.currentTimeMillis();
    long newExpiry;
    long newExpiry;
    if (time > 0L) {
      newExpiry = updated + timeunit.toMillis(time);
    } else {
      newExpiry = Long.MAX_VALUE;
    }
    expiry = Math.min(validUntil, newExpiry);
  }
  
  public boolean isExpired(long now)
  {
    return now >= expiry;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.tsccm.BasicPoolEntry
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn.tsccm;

import java.io.IOException;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Queue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.params.ConnPerRoute;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;
import org.apache.http.util.LangUtils;

@Deprecated
public class RouteSpecificPool
{
  private final Log log = LogFactory.getLog(getClass());
  protected final HttpRoute route;
  protected final int maxEntries;
  protected final ConnPerRoute connPerRoute;
  protected final LinkedList<BasicPoolEntry> freeEntries;
  protected final Queue<WaitingThread> waitingThreads;
  protected int numEntries;
  
  @Deprecated
  public RouteSpecificPool(HttpRoute route, int maxEntries)
  {
    this.route = route;
    this.maxEntries = maxEntries;
    connPerRoute = new ConnPerRoute()
    {
      public int getMaxForRoute(HttpRoute route)
      {
        return maxEntries;
      }
    };
    freeEntries = new LinkedList();
    waitingThreads = new LinkedList();
    numEntries = 0;
  }
  
  public RouteSpecificPool(HttpRoute route, ConnPerRoute connPerRoute)
  {
    this.route = route;
    this.connPerRoute = connPerRoute;
    maxEntries = connPerRoute.getMaxForRoute(route);
    freeEntries = new LinkedList();
    waitingThreads = new LinkedList();
    numEntries = 0;
  }
  
  public final HttpRoute getRoute()
  {
    return route;
  }
  
  public final int getMaxEntries()
  {
    return maxEntries;
  }
  
  public boolean isUnused()
  {
    return (numEntries < 1) && (waitingThreads.isEmpty());
  }
  
  public int getCapacity()
  {
    return connPerRoute.getMaxForRoute(route) - numEntries;
  }
  
  public final int getEntryCount()
  {
    return numEntries;
  }
  
  public BasicPoolEntry allocEntry(Object state)
  {
    if (!freeEntries.isEmpty())
    {
      ListIterator<BasicPoolEntry> it = freeEntries.listIterator(freeEntries.size());
      while (it.hasPrevious())
      {
        BasicPoolEntry entry = (BasicPoolEntry)it.previous();
        if ((entry.getState() == null) || (LangUtils.equals(state, entry.getState())))
        {
          it.remove();
          return entry;
        }
      }
    }
    if ((getCapacity() == 0) && (!freeEntries.isEmpty()))
    {
      BasicPoolEntry entry = (BasicPoolEntry)freeEntries.remove();
      entry.shutdownEntry();
      OperatedClientConnection conn = entry.getConnection();
      try
      {
        conn.close();
      }
      catch (IOException ex)
      {
        log.debug("I/O error closing connection", ex);
      }
      return entry;
    }
    return null;
  }
  
  public void freeEntry(BasicPoolEntry entry)
  {
    if (numEntries < 1) {
      throw new IllegalStateException("No entry created for this pool. " + route);
    }
    if (numEntries <= freeEntries.size()) {
      throw new IllegalStateException("No entry allocated from this pool. " + route);
    }
    freeEntries.add(entry);
  }
  
  public void createdEntry(BasicPoolEntry entry)
  {
    Args.check(route.equals(entry.getPlannedRoute()), "Entry not planned for this pool");
    numEntries += 1;
  }
  
  public boolean deleteEntry(BasicPoolEntry entry)
  {
    boolean found = freeEntries.remove(entry);
    if (found) {
      numEntries -= 1;
    }
    return found;
  }
  
  public void dropEntry()
  {
    Asserts.check(numEntries > 0, "There is no entry that could be dropped");
    numEntries -= 1;
  }
  
  public void queueThread(WaitingThread wt)
  {
    Args.notNull(wt, "Waiting thread");
    waitingThreads.add(wt);
  }
  
  public boolean hasThread()
  {
    return !waitingThreads.isEmpty();
  }
  
  public WaitingThread nextThread()
  {
    return (WaitingThread)waitingThreads.peek();
  }
  
  public void removeThread(WaitingThread wt)
  {
    if (wt == null) {
      return;
    }
    waitingThreads.remove(wt);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.tsccm.RouteSpecificPool
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn.tsccm;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.util.Args;

@Deprecated
public class BasicPoolEntryRef
  extends WeakReference<BasicPoolEntry>
{
  private final HttpRoute route;
  
  public BasicPoolEntryRef(BasicPoolEntry entry, ReferenceQueue<Object> queue)
  {
    super(entry, queue);
    Args.notNull(entry, "Pool entry");
    route = entry.getPlannedRoute();
  }
  
  public final HttpRoute getRoute()
  {
    return route;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.conn.tsccm.BasicPoolEntryRef
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.conn.tsccm;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.conn.params.ConnPerRoute;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;

@Deprecated
public class ConnPoolByRoute
  extends AbstractConnPool
{
  private final Log log = LogFactory.getLog(getClass());
  private final Lock poolLock;
  protected final ClientConnectionOperator operator;
  protected final ConnPerRoute connPerRoute;
  protected final Set<BasicPoolEntry> leasedConnections;
  protected final Queue<BasicPoolEntry> freeConnections;
  protected final Queue<WaitingThread> waitingThreads;
  protected final Map<HttpRoute, RouteSpecificPool> routeToPool;
  private final long connTTL;
  private final TimeUnit connTTLTimeUnit;
  protected volatile boolean shutdown;
  protected volatile int maxTotalConnections;
  protected volatile int numConnections;
  
  public ConnPoolByRoute(ClientConnectionOperator operator, ConnPerRoute connPerRoute, int maxTotalConnections)
  {
    this(operator, connPerRoute, maxTotalConnections, -1L, TimeUnit.MILLISECONDS);
  }
  
  public ConnPoolByRoute(ClientConnectionOperator operator, ConnPerRoute connPerRoute, int maxTotalConnections, long connTTL, TimeUnit connTTLTimeUnit)
  {
    Args.notNull(operator, "Connection operator");
    Args.notNull(connPerRoute, "Connections per route");
    poolLock = poolLock;
    leasedConnections = leasedConnections;
    this.operator = operator;
    this.connPerRoute = connPerRoute;
    this.maxTotalConnections = maxTotalConnections;
    freeConnections = createFreeConnQueue();
    waitingThreads = createWaitingThreadQueue();
    routeToPool = createRouteToPoolMap();
    this.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd