package org.apache.http.impl.conn;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.commons.logging.Log;
import org.apache.http.conn.ClientConnectionOperator;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.pool.AbstractConnPool;
import org.apache.http.pool.ConnFactory;
@Deprecated
class HttpConnPool extends AbstractConnPool<HttpRoute, OperatedClientConnection, HttpPoolEntry> {
private static final AtomicLong COUNTER = new AtomicLong();
private final Log log;
private final long timeToLive;
private final TimeUnit timeUnit;
public HttpConnPool(final Log log,
final ClientConnectionOperator connOperator,
final int defaultMaxPerRoute, final int maxTotal,
final long timeToLive, final TimeUnit timeUnit) {
super(new InternalConnFactory(connOperator), defaultMaxPerRoute, maxTotal);
this.log = log;
this.timeToLive = timeToLive;
this.timeUnit = timeUnit;
}
@Override
protected HttpPoolEntry createEntry(final HttpRoute route, final OperatedClientConnection conn) {
final String id = Long.toString(COUNTER.getAndIncrement());
return new HttpPoolEntry(this.log, id, route, conn, this.timeToLive, this.timeUnit);
}
static class InternalConnFactory implements ConnFactory<HttpRoute, OperatedClientConnection> {
private final ClientConnectionOperator connOperator;
InternalConnFactory(final ClientConnectionOperator connOperator) {
this.connOperator = connOperator;
}
@Override
public OperatedClientConnection create(final HttpRoute route) throws IOException {
return connOperator.createConnection();
}
}
}