You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2015/02/27 11:59:20 UTC
svn commit: r1662658 -
/httpcomponents/httpcore/branches/4.4.x/src/docbkx/blocking-io.xml
Author: olegk
Date: Fri Feb 27 10:59:19 2015
New Revision: 1662658
URL: http://svn.apache.org/r1662658
Log:
HTTPCORE-369: tutorial section on interaction with idle / leased connections in connection pools
Modified:
httpcomponents/httpcore/branches/4.4.x/src/docbkx/blocking-io.xml
Modified: httpcomponents/httpcore/branches/4.4.x/src/docbkx/blocking-io.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/src/docbkx/blocking-io.xml?rev=1662658&r1=1662657&r2=1662658&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/src/docbkx/blocking-io.xml (original)
+++ httpcomponents/httpcore/branches/4.4.x/src/docbkx/blocking-io.xml Fri Feb 27 10:59:19 2015
@@ -427,7 +427,7 @@ BasicPoolEntry poolEntry = future.get();
try {
HttpClientConnection conn = poolEntry.getConnection();
} finally {
- connpool.release(poolEntry, conn.isOpen());
+ connpool.release(poolEntry, true);
}
]]></programlisting>
<para>
@@ -457,6 +457,43 @@ BasicConnPool connpool = <...>
connpool.closeExpired();
connpool.closeIdle(1, TimeUnit.MINUTES);
]]></programlisting>
+ <para>
+ Generally it is considered to be a responsibility of the consumer to keep track of
+ connections leased from the pool and to ensure their immediate release as soon as they
+ are no longer needed or actively used. Nevertheless <classname>BasicConnPool </classname>
+ provides protected methods to enumerate available idle connections and those currently
+ leased from the pool. This enables the pool consumer to query connection state and
+ selectively terminate connections meeting a particular criterion.
+ </para>
+ <programlisting><![CDATA[
+static class MyBasicConnPool extends BasicConnPool {
+
+ @Override
+ protected void enumAvailable(final PoolEntryCallback<HttpHost, HttpClientConnection> callback) {
+ super.enumAvailable(callback);
+ }
+
+ @Override
+ protected void enumLeased(final PoolEntryCallback<HttpHost, HttpClientConnection> callback) {
+ super.enumLeased(callback);
+ }
+
+}
+]]></programlisting>
+ <programlisting><![CDATA[
+MyBasicConnPool connpool = new MyBasicConnPool();
+connpool.enumAvailable(new PoolEntryCallback<HttpHost, HttpClientConnection>() {
+
+ @Override
+ public void process(final PoolEntry<HttpHost, HttpClientConnection> entry) {
+ Date creationTime = new Date(entry.getCreated());
+ if (creationTime.before(someTime)) {
+ entry.close();
+ }
+ }
+
+});
+]]></programlisting>
</section>
<section>
<title>TLS/SSL support</title>