Example usage for org.apache.http.impl.nio.conn ClientConnAdaptor getEntry

List of usage examples for org.apache.http.impl.nio.conn ClientConnAdaptor getEntry

Introduction

In this page you can find the example usage for org.apache.http.impl.nio.conn ClientConnAdaptor getEntry.

Prototype

protected HttpPoolEntry getEntry() 

Source Link

Usage

From source file:org.apache.http.impl.nio.conn.PoolingClientConnectionManager.java

public void releaseConnection(final ManagedClientConnection conn, final long validDuration,
        final TimeUnit tunit) {
    if (conn == null) {
        throw new IllegalArgumentException("HTTP connection may not be null");
    }//from w  w  w . j  a va2 s  . c  o m
    if (!(conn instanceof ClientConnAdaptor)) {
        throw new IllegalArgumentException(
                "Connection class mismatch, " + "connection not obtained from this manager");
    }
    if (tunit == null) {
        throw new IllegalArgumentException("Time unit may not be null");
    }
    ClientConnAdaptor adaptor = (ClientConnAdaptor) conn;
    ClientConnectionManager manager = adaptor.getManager();
    if (manager != null && manager != this) {
        throw new IllegalArgumentException("Connection not obtained from this manager");
    }
    HttpPoolEntry entry = adaptor.getEntry();
    if (this.log.isDebugEnabled()) {
        HttpRoute route = entry.getPlannedRoute();
        Object state = entry.getState();
        this.log.debug("Releasing connection: route[" + route + "][state: " + state + "]");
        PoolStats totals = this.pool.getTotalStats();
        PoolStats stats = this.pool.getStats(route);
        this.log.debug("Total: " + totals);
        this.log.debug("Route [" + route + "]: " + stats);
    }

    boolean reusable = adaptor.isReusable();
    if (reusable) {
        entry.updateExpiry(validDuration, tunit);
        if (this.log.isDebugEnabled()) {
            String s;
            if (validDuration > 0) {
                s = "for " + validDuration + " " + tunit;
            } else {
                s = "indefinitely";
            }
            HttpRoute route = entry.getPlannedRoute();
            Object state = entry.getState();
            this.log.debug("Pooling connection" + " [" + route + "][" + state + "]; keep alive " + s);
        }
    }
    this.pool.release(entry, reusable);
}