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

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

Introduction

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

Prototype

public ClientConnectionManager getManager() 

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);
        }/* w  w  w.  j  a  v  a 2s  .  com*/
        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;
                }
            }
        }
    }
}

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

public void releaseConnection(final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {

    if (!(conn instanceof ManagedClientConnectionImpl)) {
        throw new IllegalArgumentException(
                "Connection class mismatch, " + "connection not obtained from this manager.");
    }//from  w  w w . java  2  s  .  co  m
    ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
    if (managedConn.getManager() != this) {
        throw new IllegalStateException("Connection not obtained from this manager.");
    }

    synchronized (managedConn) {
        HttpPoolEntry entry = managedConn.detach();
        if (entry == null) {
            return;
        }
        try {
            if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                try {
                    managedConn.shutdown();
                } catch (IOException iox) {
                    if (this.log.isDebugEnabled()) {
                        this.log.debug("I/O exception shutting down released connection", iox);
                    }
                }
            }
            entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
            if (this.log.isDebugEnabled()) {
                String s;
                if (keepalive > 0) {
                    s = "for " + keepalive + " " + tunit;
                } else {
                    s = "indefinitely";
                }
                this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
            }
        } finally {
            this.pool.release(entry, managedConn.isMarkedReusable());
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
        }
    }
}

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

@Override
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;
    Asserts.check(managedConn.getManager() == this, "Connection not obtained from this manager");
    synchronized (managedConn) {
        final HttpPoolEntry entry = managedConn.detach();
        if (entry == null) {
            return;
        }//from   w w w  .j  a v a2s .  c o m
        try {
            if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                try {
                    managedConn.shutdown();
                } catch (final IOException iox) {
                    if (this.log.isDebugEnabled()) {
                        this.log.debug("I/O exception shutting down released connection", iox);
                    }
                }
            }
            // Only reusable connections can be kept alive
            if (managedConn.isMarkedReusable()) {
                entry.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 " + format(entry) + " can be kept alive " + s);
                }
            }
        } finally {
            this.pool.release(entry, managedConn.isMarkedReusable());
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
        }
    }
}

From source file:org.apache.http.impl.conn.PoolingClientConnectionManager.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;
    Asserts.check(managedConn.getManager() == this, "Connection not obtained from this manager");
    synchronized (managedConn) {
        final HttpPoolEntry entry = managedConn.detach();
        if (entry == null) {
            return;
        }/*from w ww  .j  a  v a 2s. c  o m*/
        try {
            if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
                try {
                    managedConn.shutdown();
                } catch (final IOException iox) {
                    if (this.log.isDebugEnabled()) {
                        this.log.debug("I/O exception shutting down released connection", iox);
                    }
                }
            }
            // Only reusable connections can be kept alive
            if (managedConn.isMarkedReusable()) {
                entry.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 " + format(entry) + " can be kept alive " + s);
                }
            }
        } finally {
            this.pool.release(entry, managedConn.isMarkedReusable());
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
        }
    }
}