Hi,
I'm looking for a way to implement some kind of ping/keep-alive policy on a pool of network connections. That is, if a connection in the pool has not been claimed after a given amount of time, it should automatically send a ping request to the server to maintain that connection and make sure it's still working and ready to be used. FTR I'd like to have a pool of exactly N connections at all times, ready to be used.
I guess I could hack an ExpirationPolicy to check if a connection has not been used in a while and send that ping in hasExpired(), but I'm wondering if it's the right place to make such time-consuming tasks. If I have 10 connections that need 50ms each to send a ping, then claimLock is held for 500ms, during which other threads cannot claim other objects.
Maybe having a way to claim a specific PoolableObject from the pool would be a better approach: an expiration policy checks for connections that haven't been used in a while, adds them to a queue and a background thread claims them one at a time to send the ping?
Hi,
I'm looking for a way to implement some kind of ping/keep-alive policy on a pool of network connections. That is, if a connection in the pool has not been claimed after a given amount of time, it should automatically send a ping request to the server to maintain that connection and make sure it's still working and ready to be used. FTR I'd like to have a pool of exactly N connections at all times, ready to be used.
I guess I could hack an
ExpirationPolicyto check if a connection has not been used in a while and send that ping inhasExpired(), but I'm wondering if it's the right place to make such time-consuming tasks. If I have 10 connections that need 50ms each to send a ping, thenclaimLockis held for 500ms, during which other threads cannot claim other objects.Maybe having a way to claim a specific
PoolableObjectfrom the pool would be a better approach: an expiration policy checks for connections that haven't been used in a while, adds them to a queue and a background thread claims them one at a time to send the ping?