hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1662658 - /httpcomponents/httpcore/branches/4.4.x/src/docbkx/blocking-io.xml
Date Fri, 27 Feb 2015 10:59:20 GMT
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>



Mime
View raw message