Hi, all

        When I use httpasyncclient-4.0.1 for developing, I find one question 
for keep alive connection.


        After processing one request, the connection manager will retrieve the 
connection. 


        However, the ConnectionKeepAliveStrategy is not take effect, the 
connection will be timeout using socket timeout value, not until the value 
strategy is given.


        By reading httpasyncclient code, I find the Deprecated class 
PoolingClientAsyncConnectionManager do the right thing:
            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());
            }




        The new PoolingNHttpClientConnectionManager class do not contain this 
code. So the connection will use the socket timeout config, close shortly. Then 
I add same code on PoolingNHttpClientConnectionManager, everything goes ok 
now...
            try {
                if (conn.isOpen()) {
                    entry.setState(state);
                    log.debug("yyyyy keepalive: " + keepalive);
                    entry.updateExpiry(keepalive, tunit != null ? tunit : 
TimeUnit.MILLISECONDS);
                    if (this.log.isDebugEnabled()) {
                        final String s;
                        if (keepalive > 0) {
                            s = "for " + (double) keepalive / 1000 + " seconds";
                        } else {
                            s = "indefinitely";
                        }
                        this.log.debug("Connection " + format(entry) + " can be 
kept alive " + s);
                        conn.setSocketTimeout(0);
                    }
                }
            } finally {
                this.pool.release(entry, conn.isOpen() && 
entry.isRouteComplete());
                if (this.log.isDebugEnabled()) {
                    this.log.debug("Connection released: " + format(entry) + 
formatStats(entry.getRoute()));
                }
            }


        Can anyone tell me whether I do the right change ? 




        Thanks!

Reply via email to