AbstractPoolEntrypublic abstract class AbstractPoolEntry extends Object A pool entry for use by connection manager implementations.
Pool entries work in conjunction with an
{@link AbstractClientConnAdapter adapter}.
The adapter is handed out to applications that obtain a connection.
The pool entry stores the underlying connection and tracks the
{@link HttpRoute route} established.
The adapter delegates methods for establishing the route to
it's pool entry.
If the managed connections is released or revoked, the adapter
gets disconnected, but the pool entry still contains the
underlying connection and the established route. |
Fields Summary |
---|
protected final ClientConnectionOperator | connOperatorThe connection operator. | protected final OperatedClientConnection | connectionThe underlying connection being pooled or used. | protected volatile HttpRoute | routeThe route for which this entry gets allocated. | protected volatile Object | stateConnection state object | protected volatile RouteTracker | trackerThe tracked route, or null before tracking starts. |
Constructors Summary |
---|
protected AbstractPoolEntry(ClientConnectionOperator connOperator, HttpRoute route)Creates a new pool entry.
super();
if (connOperator == null) {
throw new IllegalArgumentException("Connection operator may not be null");
}
this.connOperator = connOperator;
this.connection = connOperator.createConnection();
this.route = route;
this.tracker = null;
|
Methods Summary |
---|
public java.lang.Object | getState()Returns the state object associated with this pool entry.
return state;
| public void | layerProtocol(org.apache.http.protocol.HttpContext context, org.apache.http.params.HttpParams params)Layers a protocol on top of an established tunnel.
//@@@ is context allowed to be null? depends on operator?
if (params == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
if ((this.tracker == null) || !this.tracker.isConnected()) {
throw new IllegalStateException("Connection not open.");
}
if (!this.tracker.isTunnelled()) {
//@@@ allow this?
throw new IllegalStateException
("Protocol layering without a tunnel not supported.");
}
if (this.tracker.isLayered()) {
throw new IllegalStateException
("Multiple protocol layering not supported.");
}
// - collect the arguments
// - call the operator
// - update the tracking data
// In this order, we can be sure that only a successful
// layering on top of the connection will be tracked.
final HttpHost target = tracker.getTargetHost();
connOperator.updateSecureConnection(this.connection, target,
context, params);
this.tracker.layerProtocol(this.connection.isSecure());
| public void | open(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context, org.apache.http.params.HttpParams params)Opens the underlying connection.
if (route == null) {
throw new IllegalArgumentException
("Route must not be null.");
}
//@@@ is context allowed to be null? depends on operator?
if (params == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
if ((this.tracker != null) && this.tracker.isConnected()) {
throw new IllegalStateException("Connection already open.");
}
// - collect the arguments
// - call the operator
// - update the tracking data
// In this order, we can be sure that only a successful
// opening of the connection will be tracked.
//@@@ verify route against planned route?
this.tracker = new RouteTracker(route);
final HttpHost proxy = route.getProxyHost();
connOperator.openConnection
(this.connection,
(proxy != null) ? proxy : route.getTargetHost(),
route.getLocalAddress(),
context, params);
RouteTracker localTracker = tracker; // capture volatile
// If this tracker was reset while connecting,
// fail early.
if (localTracker == null) {
throw new IOException("Request aborted");
}
if (proxy == null) {
localTracker.connectTarget(this.connection.isSecure());
} else {
localTracker.connectProxy(proxy, this.connection.isSecure());
}
| public void | setState(java.lang.Object state)Assigns a state object to this pool entry.
this.state = state;
| protected void | shutdownEntry()Shuts down the entry.
If {@link #open(HttpRoute, HttpContext, HttpParams)} is in progress,
this will cause that open to possibly throw an {@link IOException}.
tracker = null;
| public void | tunnelProxy(org.apache.http.HttpHost next, boolean secure, org.apache.http.params.HttpParams params)Tracks tunnelling of the connection to a chained proxy.
The tunnel has to be established outside by sending a CONNECT
request to the previous proxy.
if (next == null) {
throw new IllegalArgumentException
("Next proxy must not be null.");
}
if (params == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
//@@@ check for proxy in planned route?
if ((this.tracker == null) || !this.tracker.isConnected()) {
throw new IllegalStateException("Connection not open.");
}
// LOG.debug?
this.connection.update(null, next, secure, params);
this.tracker.tunnelProxy(next, secure);
| public void | tunnelTarget(boolean secure, org.apache.http.params.HttpParams params)Tracks tunnelling of the connection to the target.
The tunnel has to be established outside by sending a CONNECT
request to the (last) proxy.
if (params == null) {
throw new IllegalArgumentException
("Parameters must not be null.");
}
//@@@ check for proxy in planned route?
if ((this.tracker == null) || !this.tracker.isConnected()) {
throw new IllegalStateException("Connection not open.");
}
if (this.tracker.isTunnelled()) {
throw new IllegalStateException
("Connection is already tunnelled.");
}
// LOG.debug?
this.connection.update(null, tracker.getTargetHost(),
secure, params);
this.tracker.tunnelTarget(secure);
|
|