Resource adapters are an awesome way to interact with a container to get services. (see http://blog.dblevins.com/2010/10/ejbnext-connectorbean-api-jax-rs-and.html if you doubt about it). We recently worked on TomEE to make it more powerful and usable than it was before.
First to deploy a resource adapter (rar) on TomEE simply add in conf/tomee.xml the line:
<Deployments file="/path/to/my/super-ra.rar" />
Secondly on TomEE (not sure on other servers) you were able to deploy a resource adapter only once by path (physical location). You can now deploy a resource adapter N times using the system property (put it in conf/system.properties for convenience):
openejb.connector.<id>.aliases = ... openejb.connector.<id>.skip-default = [true|false]
The first property list aliases of this connector. The second configure the fact to keep the default deployment or not. In our case it will look like:
openejb.connector.super-ra.aliases = ra1, ra2, ra3 openejb.connector.super-ra.skip-default = true
It will deploy our resource adapter as ra1, ra2, ra3.
You can still configure the resource adapter instances as before using properties like:
<name>.<property> = <value>
For instance to configure MySQL tranql resource adapter (wraps datasource in resource adapters) you can do:
<?xml version="1.0" encoding="UTF-8"?> <openejb> <Deployments file="tranql-connector-mysql-xa-1.6.rar" /> </openejb>
openejb.connector.tranql-connector-mysql-xa-1.6.aliases = foo, bar openejb.connector.tranql-connector-mysql-xa-1.6.skip-default = true foo.ServerName = localhost foo.UserName = root foo.Password = pwd foo.DatabaseName = test bar.ServerName = localhost bar.UserName = root bar.Password = pwd bar.DatabaseName = test
Finally in the case of tranql you get ManagedConnectionFactories which are javax.sql.DataSource. So you can simply reuse them in you rpersistence-units as jta-data-source (foo, bar…).
Is there a way to pool the connections?
This is a question more for tranql or the RA impl. TomEE has dbcp and tomcat pool impl with XA support but it doesnt use a RA.
But, if I configure my rar this way I get some sort of connection management (The connection gets automatically created and destroyed). Is there a way to configure the idle timeout before closing the connection, for example?
If you speak of tranql connection management it is on their forum you nees to ask. But any pool has such config normally. For datasources native tomee support can be better and you inherit of native pooling.
I’m trying to use a rar I have created (it connects to some specfic systems using different APIs, not JDBC). What I’m trying to do is to create different pools of connections of this RA, each pool has different connection properties). I don’t know if the method you describe in this article is the best way to do it.
And I want to access the pools of connections of my RA from session beans.
This is done through your RA API but if you want some RA pooling (for datasource the pooling is behind generally) you can use some advanced properties like https://github.com/apache/tomee/blob/master/container/openejb-core/src/main/java/org/apache/openejb/resource/GeronimoConnectionManagerFactory.java#L264 (see partitionStrategy. Default impl is https://github.com/apache/geronimo/blob/1.0/modules/connector/src/java/org/apache/geronimo/connector/outbound/connectionmanagerconfig/SinglePool.java
Thanks for your help! that’s what I was looking for.