Example usage for org.apache.http.impl.nio.conn ManagedClientAsyncConnectionImpl setSocketTimeout

List of usage examples for org.apache.http.impl.nio.conn ManagedClientAsyncConnectionImpl setSocketTimeout

Introduction

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

Prototype

@Override
    public void setSocketTimeout(final int timeout) 

Source Link

Usage

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

@Override
public void releaseConnection(final ManagedClientAsyncConnection conn, final long keepalive,
        final TimeUnit tunit) {
    Args.notNull(conn, "HTTP connection");
    if (!(conn instanceof ManagedClientAsyncConnectionImpl)) {
        throw new IllegalArgumentException(
                "Connection class mismatch, " + "connection not obtained from this manager");
    }/*from   w  w w .  j  a  v  a2s  .c  o m*/
    Args.notNull(tunit, "Time unit");
    final ManagedClientAsyncConnectionImpl managedConn = (ManagedClientAsyncConnectionImpl) conn;
    final ClientAsyncConnectionManager manager = managedConn.getManager();
    if (manager != null && manager != this) {
        throw new IllegalArgumentException("Connection not obtained from this manager");
    }
    if (this.pool.isShutdown()) {
        return;
    }

    synchronized (managedConn) {
        final HttpPoolEntry entry = managedConn.getPoolEntry();
        if (entry == null) {
            return;
        }
        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);
                    }
                }
            }
            if (managedConn.isOpen()) {
                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);
                }
                // Do not time out pooled connection
                managedConn.setSocketTimeout(0);
            }
        } finally {
            this.pool.release(managedConn.detach(), managedConn.isMarkedReusable());
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
        }
    }
}