The JCA container calls matchManagedConnections() in order to verify if a ManagedConnection can be reused - see http://docs.jboss.org/ironjacamar/userguide/1.1/en-US/html/samples.html#sample_helloworld_mcf. In most cases you would use the Subject and/or CRI to verify a match.
The ValidatingManagedConnectionFactory interface can be implemented in order to help the JCA container to clean up unneeded managed connections.
Thank you for your respond but I have a problem that these methods are not called by JCA container.
I implemented both of them for better connection reuse but these methods are never called and I don't know why?
Please, go through the HelloWorld example first.
I have already went through example several times, I will try it again - please, could you focus me where could be the problem?
It could be a ton of different things - have you implemented ConnectionEventListener interaction correct, have you a correct pool setup, are the background validation parameters set, and so on.
I generated RA skeleton with code generator (like follows) and I would expect that everything was corretly generated:
marti-pc:codegenerator pjuza$ sh ./codegenerator.sh
Profile version (1.6/1.5/1.0) [1.6]: 1.5
Type (O/Outbound/I/Inbound/B/Bidirectional) [O]:
Package name: com.cleverlance.smartclient.ra.httpclient
Transaction support (N/NoTransaction/L/LocalTransaction/X/XATransaction) [N]:
Support reauthentication (Y/Yes/N/No) [N]:
Include a ResourceAdapter (Y/Yes/N/No) [Y]:
Resource adapter class name [AcmeResourceAdapter]: HttpClientResourceAdapterImpl
Resource adapter config properties [enter to quit]:
Managed connection factory class name [AcmeManagedConnectionFactory]: HttpClientResourceAdapterImpl
Managed connection factory config properties [enter to quit]:
Use ResourceAdapterAssociation (Y/Yes/N/No) [Y]:
Managed connection class name [AcmeManagedConnection]: HttpClientManagedConnectionImpl
Use CCI (Y/Yes/N/No) [N]:
Connection factory interface class name [AcmeConnectionFactory]: HttpClientRaConnectionFactory
Connection factory implementation class name [AcmeConnectionFactoryImpl]: HttpClientRaConnectionFactoryImpl
Connection interface class name [AcmeConnection]: ManagedClientConnection
Connection implementation class name [AcmeConnectionImpl]: ManagedClientConnectionImpl
Add methods to connection interface (Y/Yes/N/No) [N]:
Additional managed connection factory (Y/Yes/N/No) [N]:
Include an admin object (Y/Yes/N/No) [N]:
Generate a MBean class (Y/Yes/N/No) [Y]:
Build environment [A/Ant/I/Ant+Ivy/M/Maven] [A]: M
I have been trying to change settings in ironjacamar.xml but without positive results. I doubt if matching connection is possible for non-datasource connections? And if it's true then it is specific for ironjacamar only or is it general JCA contract?
I will reply to myself - I read JCA specification and I found:
"Connection Matching Contract
The application server invokes the ManagedConnectionFactory.matchManagedConnections method (implemented by a resource adapter) to find a matching ManagedConnection for servicing a connection request. The application server passes a candidate set of ManagedConnection instances to the matchManagedConnections method.
The application server should use the connection matching contract for ManagedConnection instances that have no existing connection handles. A candidate set passed to the matchManagedConnections method should not have any ManagedConnection instances with existing connection handles."
Now ManagedConnectionFactory.matchManagedConnections is called.
I found the following about ResourceAdapterAssociation.getInvalidConnections:
"This optional functionality may be used by the application server to prune invalid ManagedConnection objects from its connection pool periodically."
Is this interface/functionality supported by IronJacamar?
Yes, enable background validation and set the frequency.