Example usage for org.apache.http.impl.conn ManagedClientConnectionImpl getPoolEntry

List of usage examples for org.apache.http.impl.conn ManagedClientConnectionImpl getPoolEntry

Introduction

In this page you can find the example usage for org.apache.http.impl.conn ManagedClientConnectionImpl getPoolEntry.

Prototype

HttpPoolEntry getPoolEntry() 

Source Link

Usage

From source file:org.apache.http.impl.conn.BasicClientConnectionManager.java

public void releaseConnection(final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
    Args.check(conn instanceof ManagedClientConnectionImpl,
            "Connection class mismatch, " + "connection not obtained from this manager");
    final ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
    synchronized (managedConn) {
        if (this.log.isDebugEnabled()) {
            this.log.debug("Releasing connection " + conn);
        }/*from  w w  w. j a  va2  s .  c  o m*/
        if (managedConn.getPoolEntry() == null) {
            return; // already released
        }
        final ClientConnectionManager manager = managedConn.getManager();
        Asserts.check(manager == this, "Connection not obtained from this manager");
        synchronized (this) {
            if (this.shutdown) {
                shutdownConnection(managedConn);
                return;
            }
            try {
                if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                    shutdownConnection(managedConn);
                }
                if (managedConn.isMarkedReusable()) {
                    this.poolEntry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
                    if (this.log.isDebugEnabled()) {
                        final String s;
                        if (keepalive > 0) {
                            s = "for " + keepalive + " " + tunit;
                        } else {
                            s = "indefinitely";
                        }
                        this.log.debug("Connection can be kept alive " + s);
                    }
                }
            } finally {
                managedConn.detach();
                this.conn = null;
                if (this.poolEntry.isClosed()) {
                    this.poolEntry = null;
                }
            }
        }
    }
}