if (service instanceof ResourceAdapter) {
ResourceAdapter resourceAdapter = (ResourceAdapter) service;
// resource adapters only work with a geronimo transaction manager
if (!(transactionManager instanceof GeronimoTransactionManager)) {
throw new OpenEJBException("The use of a resource adapter requires a Geronimo transaction manager");
}
GeronimoTransactionManager geronimoTransactionManager = (GeronimoTransactionManager) transactionManager;
// create a thead pool
int threadPoolSize = getIntProperty(serviceInfo.properties, "threadPoolSize", 30);
if (threadPoolSize <= 0) throw new IllegalArgumentException("threadPoolSizes <= 0: " + threadPoolSize);
Executor threadPool = Executors.newFixedThreadPool(threadPoolSize, new ResourceAdapterThreadFactory(serviceInfo.id));
// create a work manager which the resource adapter can use to dispatch messages or perform tasks
WorkManager workManager = new GeronimoWorkManager(threadPool, threadPool, threadPool, geronimoTransactionManager);
// wrap the work mananger and transaction manager in a bootstrap context (connector spec thing)
BootstrapContext bootstrapContext = new GeronimoBootstrapContext(workManager, geronimoTransactionManager);
// start the resource adapter
try {
resourceAdapter.start(bootstrapContext);
} catch (ResourceAdapterInternalException e) {
throw new OpenEJBException(e);
}
} else if (service instanceof ManagedConnectionFactory) {
ManagedConnectionFactory managedConnectionFactory = (ManagedConnectionFactory) service;
// get the connection manager
ConnectionManager connectionManager;
if ((ManagedConnectionFactory) service instanceof JdbcManagedConnectionFactory) {
connectionManager = SystemInstance.get().getComponent(ConnectionManager.class);
} else {
GeronimoConnectionManagerFactory connectionManagerFactory = new GeronimoConnectionManagerFactory();
// default transaction support is "local" and that doesn't seem to work
connectionManagerFactory.setTransactionSupport("xa");
connectionManagerFactory.setTransactionManager(transactionManager);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) classLoader = getClass().getClassLoader();
if (classLoader == null) classLoader = ClassLoader.getSystemClassLoader();
connectionManagerFactory.setClassLoader(classLoader);
connectionManager = connectionManagerFactory.create();
}
if (connectionManager == null) {
throw new RuntimeException("Invalid connection manager specified for connector identity = " + serviceInfo.id);
}
// service becomes a ConnectorReference which merges connection manager and mcf
service = new ConnectorReference(connectionManager, managedConnectionFactory);
}
try {
containerSystem.getJNDIContext().bind("java:openejb/Resource/" + serviceInfo.id, service);
} catch (NamingException e) {
throw new OpenEJBException("Cannot bind resource adapter with id " + serviceInfo.id, e);
}
// Update the config tree
config.facilities.resources.add(serviceInfo);
}