On Thu, 2015-02-19 at 14:10 +0000, Pedro Ribeiro wrote: > Hi Oleg, > > Thank you very much for your reply. > > That's exactly what I was thinking, but instead of using enumAvailable > which blocks access to the pool, I would lock and get a copy of *available* > List*.* Then, for each connection available, try to lease one by one. > If the connection is not available anymore (we might have stale information > because we are outside the lock) continue otherwise send a keep-alive. > > Would you be interested in a patch for this feature? >
Pedro, The problem with this approach is that one cannot lease a specific connection. One can only lease an arbitrary connection matching the lease criteria: route and state. A much simpler solution to your problem might be just leasing, say, 5 connections every 5 minutes, sending a ping message on all them and releasing them all back to the pool. This way your application would always have approximately 5 live connections. Oleg > On Thu, Feb 19, 2015 at 1:33 PM, Oleg Kalnichevski <[email protected]> wrote: > > > On Wed, 2015-02-18 at 19:46 +0000, Pedro Ribeiro wrote: > > > Hi, > > > > > > I'm using http client with a connection pool to execute RPCs in a remove > > > host which drops connections after 1 min of inactivity. > > > In my use case It’s really expensive to establish new connections so I > > > would like to send a keepalive message from every open connection before > > > expiration. > > > > > > I've looked into the source of PoolingHttpClientConnectionManager and > > > unfortunately I didn't find a way to implement this feature reusing > > > existing pool implementation. I though in wrapping > > > PoolingHttpClientConnectionManager and assigning a state to uniquely > > > identify connections and request them when they are about to expire but > > > it’s not the way to go. The state of the connection wasn't meant to be > > used > > > this way. > > > > > > I don’t see any other option other than changing > > > org.apache.http.pool.AbstractConnPool and add a new method with a > > callback > > > to run on every active connection. > > > I cannot use org.apache.http.pool.AbstractConnPool.enumAvailable because > > > it’s too expensive. It locks the pool while the callbacks are running. I > > > was thinking in copying the list of available connections (with lock) and > > > try to lease and send my request one by one. > > > > > > Any other suggestion? > > > > > > Thank you. > > > > Pedro, > > > > Please note that when kept in the pool persistent connections are not > > able to send or receive data. They are just sitting there idly not being > > attached to a particular thread of execution. This is a general > > limitation of the classic (blocking) Java I/O. In order to be able send > > and receive a keep-alive message one has to lease a connection from the > > pool (or do it from #enumAvailable for all connections blocking access > > to the pool from all other threads in the process). > > > > Oleg > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
