Many Connections to one ManagedConnection
andrew_m Sep 14, 2002 7:55 AMJboss version : 3.0.1_tomcat4.0.4
We have created a resource adapter which connects to a network node which implements its own security protocol. Each client of this system has an id which we have wrapped up and pass as the criteria to getConnection(). We have Jboss configured to allocation connections based on our criteria i.e. ByApplication. One of our requirements is that all calls to getConnection() with the same criteria result in obtaining a connection associated to the same ManagedConnection i.e. potentially one-to-many.
I have tried several different ways to get this to work, but it seems from examining the code that the default behaviour is to create a new ManagedConnection instance if there is already a Connection handle associated with the one we want. This arises because JBoss separates out the ManagedConnection pool based on the configuration (ByApplication in our case) and once one is checked out that is it - it won't attempt to match it again until cleanup() has been called after the associated connection handle has been closed. (This happens in more than one thread)
I understand from previous postings from David that the reason for matchManagedConnection only being called with one (already matched effectively) ManagedConnection is to improve concurrency, but I can't see a "safe" way to have a many to one relationship. The only thing we have got to work is to modify the behaviour of createManagedConnection to return a matching one if it already exists. This is obviously incorrect as it is the behaviour that I would expect from matchManagedConnection instead. Am I missing somthing or is there something we can configure differently?
Sorry for the very wordy post but I wanted to make clear that I understand the implications of open connection handles etc. I have tried to summarize below.
Current behaviour
Bean 1 calls getConnection()
Correct ManagedConnection is returned
Bean 2 calls getConnection with same criteria
New ManagedConnection created
Both call close
cleanup() called on both ManagedConnections
Desired behaviour
Bean 1 calls getConnection()
Correct ManagedConnection is returned
Bean 2 calls getConnection with same criteria
Same ManagedConnection created
Bean 1 calls close()
Nothing happens
Bean 2 calls close()
cleanup() called on ManagedConnection
Regards,
Andrew