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]

Reply via email to