List of usage examples for org.apache.http.impl.conn ManagedClientConnectionImpl shutdown
public void shutdown() throws IOException
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."); }// ww w . j a va 2s .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 ww. ja v a 2 s . co 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 ww w . jav a 2 s . 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())); } } }