Example usage for org.apache.http.impl.nio.conn CPoolProxy detach

List of usage examples for org.apache.http.impl.nio.conn CPoolProxy detach

Introduction

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

Prototype

public static CPoolEntry detach(final NHttpClientConnection proxy) 

Source Link

Usage

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

@Override
public void releaseConnection(final NHttpClientConnection managedConn, final Object state, final long keepalive,
        final TimeUnit tunit) {
    Args.notNull(managedConn, "Managed connection");
    synchronized (managedConn) {
        final CPoolEntry entry = CPoolProxy.detach(managedConn);
        if (entry == null) {
            return;
        }//from  ww w. j ava  2s.com
        if (this.log.isDebugEnabled()) {
            this.log.debug("Releasing connection: " + format(entry) + formatStats(entry.getRoute()));
        }
        final NHttpClientConnection conn = entry.getConnection();
        try {
            if (conn.isOpen()) {
                entry.setState(state);
                entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
                if (this.log.isDebugEnabled()) {
                    final String s;
                    if (keepalive > 0) {
                        s = "for " + (double) keepalive / 1000 + " seconds";
                    } else {
                        s = "indefinitely";
                    }
                    this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
                }
            }
        } finally {
            this.pool.release(entry, conn.isOpen() && entry.isRouteComplete());
            if (this.log.isDebugEnabled()) {
                this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
            }
        }
    }
}