Example usage for org.apache.http.impl.conn.tsccm BasicPooledConnAdapter getManager

List of usage examples for org.apache.http.impl.conn.tsccm BasicPooledConnAdapter getManager

Introduction

In this page you can find the example usage for org.apache.http.impl.conn.tsccm BasicPooledConnAdapter getManager.

Prototype

@Override
    protected ClientConnectionManager getManager() 

Source Link

Usage

From source file:org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.java

public void releaseConnection(final ManagedClientConnection conn, final long validDuration,
        final TimeUnit timeUnit) {
    Args.check(conn instanceof BasicPooledConnAdapter,
            "Connection class mismatch, " + "connection not obtained from this manager");
    final BasicPooledConnAdapter hca = (BasicPooledConnAdapter) conn;
    if (hca.getPoolEntry() != null) {
        Asserts.check(hca.getManager() == this, "Connection not obtained from this manager");
    }/*from  w w  w  .j a v a 2 s  . co m*/
    synchronized (hca) {
        final BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
        if (entry == null) {
            return;
        }
        try {
            // make sure that the response has been read completely
            if (hca.isOpen() && !hca.isMarkedReusable()) {
                // In MTHCM, there would be a call to
                // SimpleHttpConnectionManager.finishLastResponse(conn);
                // Consuming the response is handled outside in 4.0.

                // make sure this connection will not be re-used
                // Shut down rather than close, we might have gotten here
                // because of a shutdown trigger.
                // Shutdown of the adapter also clears the tracked route.
                hca.shutdown();
            }
        } catch (final IOException iox) {
            if (log.isDebugEnabled()) {
                log.debug("Exception shutting down released connection.", iox);
            }
        } finally {
            final boolean reusable = hca.isMarkedReusable();
            if (log.isDebugEnabled()) {
                if (reusable) {
                    log.debug("Released connection is reusable.");
                } else {
                    log.debug("Released connection is not reusable.");
                }
            }
            hca.detach();
            pool.freeEntry(entry, reusable, validDuration, timeUnit);
        }
    }
}