[jboss-svn-commits] JBL Code SVN: r30415 - labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Dec 1 12:40:50 EST 2009
Author: whitingjr
Date: 2009-12-01 12:40:50 -0500 (Tue, 01 Dec 2009)
New Revision: 30415
Modified:
labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java
Log:
Added connection pooling to profiling framework.
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java 2009-12-01 17:15:54 UTC (rev 30414)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/main/java/org/jboss/jbossts/performance/TransactionXADataSourceFactory.java 2009-12-01 17:40:50 UTC (rev 30415)
@@ -22,121 +22,195 @@
package org.jboss.jbossts.performance;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.util.Hashtable;
+import java.util.Map;
+import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.Name;
import javax.naming.NamingException;
+import javax.resource.ResourceException;
+import javax.resource.spi.ConnectionManager;
+import javax.resource.spi.ConnectionRequestInfo;
+import javax.resource.spi.ManagedConnectionFactory;
+import javax.transaction.TransactionManager;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.jboss.deployment.DeploymentException;
import org.jboss.jbossts.tomcat.TransactionalResourceFactory;
-import org.jboss.jbossts.tomcat.XADataSourceWrapper;
+import org.jboss.resource.adapter.jdbc.xa.XAManagedConnectionFactory;
+import org.jboss.resource.connectionmanager.CachedConnectionManager;
+import org.jboss.resource.connectionmanager.CachedConnectionManagerReference;
+import org.jboss.resource.connectionmanager.InternalManagedConnectionPool;
+import org.jboss.resource.connectionmanager.JBossManagedConnectionPool;
+import org.jboss.resource.connectionmanager.TxConnectionManager;
import org.jboss.util.naming.NonSerializableFactory;
import org.jboss.util.naming.Util;
+
public class TransactionXADataSourceFactory extends TransactionalResourceFactory
{
private static Logger logger = Logger.getLogger(TransactionXADataSourceFactory.class);
+ private final org.jboss.logging.Logger jbLogger = org.jboss.logging.Logger.getLogger(TransactionXADataSourceFactory.class);
private String jndiName;
private InitialContext initialContext;
- private Hashtable contextProperties;
- private XADataSourceWrapper xaDataSource;
+ private Hashtable initialContextProperties;
+ private Object xaDataSource;
+ private XAManagedConnectionFactory managedConnectionFactory = new XAManagedConnectionFactory();
+ CachedConnectionManager cachedConnectionManager;
+ private InternalManagedConnectionPool.PoolParams poolParams = new InternalManagedConnectionPool.PoolParams();
+ private JBossManagedConnectionPool.OnePool pool = new JBossManagedConnectionPool.OnePool(this.managedConnectionFactory, this.poolParams, false, jbLogger);
+ private TxConnectionManager connectionManager;
+ private TransactionManager transactionManager;
+ private Map<String, String> daProperties;
- public TransactionXADataSourceFactory(String jndi, XADataSourceWrapper wrapper)
+
+ public TransactionManager getTransactionManager()
{
- this.jndiName = jndi;
- this.xaDataSource = wrapper;
+ return transactionManager;
}
-
- public void start() throws Exception
+
+ public void setTransactionManager(TransactionManager transactionManager)
{
- logger.info("Start called on transactional factory.");
- this.initialContext = new InitialContext(this.contextProperties);
- bindConnectionFactory();
+ this.transactionManager = transactionManager;
}
-
- protected void unbindConnectionFactory() throws Exception
+
+ public TransactionXADataSourceFactory(String jndi, Map<String, String> datasourceProperties)
{
- try
- {
- this.initialContext.unbind(jndiName);
- NonSerializableFactory.unbind( jndiName);
- logger.info("Unbound datasource for JNDI name '" + jndiName + "'");
- }
- catch (NamingException ne)
- {
- logger.error("Could not unbind datasource from jndi: " + convertName(jndiName), ne);
- }
- finally
- {
- this.initialContext.close();
- }
+ this.jndiName = jndi;
+ this.daProperties = datasourceProperties;
}
-
- public void bindConnectionFactory( ) throws Exception
+ public void start() throws Exception
{
-
- try
- {
- Name name = this.initialContext.getNameParser("").parse( jndiName);
- String key = name.toString();
- if( true == true && name.size() > 1 )
+ logger.info("Start called on transactional factory.");
+ this.connectionManager = new TxConnectionManager(this.cachedConnectionManager, this.pool, this.transactionManager);
+ this.connectionManager.setLocalTransactions(false);
+ this.connectionManager.setTrackConnectionByTx(true);
+ this.pool.setConnectionListenerFactory(connectionManager);
+ this.xaDataSource = this.connectionManager.getPoolingStrategy().getManagedConnectionFactory().createConnectionFactory(new ConnectionManagerDelegate());
+ if (null != this.daProperties)
+ {/* Here use a Properties object to correctly format a properties file, use store to generate
+ the file contents and convert to a string, which is passed to the setXADataSourceProperties method.
+ There are few (any?) alternatives other than this method.*/
+ Properties properties = new Properties();
+ for (String key : this.daProperties.keySet())
{
- int size = name.size() - 1;
- Util.createSubcontext(this.initialContext, name.getPrefix(size));
+ properties.put(key, this.daProperties.get(key));
}
- NonSerializableFactory.rebind(this.initialContext, key, this.xaDataSource);
- logger.info("Bound datasource to JNDI name '" + key+ "'");
+ OutputStream oStream = null;
+ try
+ {
+ oStream = new ByteArrayOutputStream();
+ properties.store(oStream, "");
+ this.managedConnectionFactory.setXADataSourceProperties(StringUtils.replace(oStream.toString(), "\\", "") );
+ }
+ catch (IOException ioe)
+ {
+ logger.error(ioe.getMessage(), ioe);
+ }
+ finally
+ {
+ IOUtils.closeQuietly(oStream);
+ }
}
- catch (NamingException ne)
- {
- throw new DeploymentException("Could not bind ConnectionFactory into jndi: " + jndiName, ne);
- }
- finally
- {
- this.initialContext.close();
- }
}
- public XADataSourceWrapper getDatasource()
+ public Object getDatasource()
{
return this.xaDataSource;
}
-
-
public String getName()
{
return jndiName;
}
+ public void setName(String name)
+ {
+ this.jndiName = name;
+ }
+ public InitialContext getInitialContext()
+ {
+ return this.initialContext;
+ }
+ public void setInitialContextProperties(Hashtable properties)
+ {
+ this.initialContextProperties = properties;
+ }
+ public int getMinSize()
+ {
+ return this.poolParams.minSize;
+ }
+ public void setMinSize(int minSize)
+ {
+ this.poolParams.minSize = minSize;
+ }
- public void setName(String name)
+ public int getMaxSize()
{
- this.jndiName = name;
+ return this.poolParams.maxSize;
}
+ public void setMaxSize(int maxSize)
+ {
+ this.poolParams.maxSize = maxSize;
+ }
- public InitialContext getInitialContext()
+ public int getBlockingTimeout()
{
- return initialContext;
+ return this.poolParams.blockingTimeout;
}
+ public void setBlockingTimeout(int blockingTimeout)
+ {
+ this.poolParams.blockingTimeout = blockingTimeout;
+ }
- public void setInitialContext(InitialContext initialContext)
+ public long getIdleTimeout()
{
- this.initialContext = initialContext;
+ return this.poolParams.idleTimeout;
}
- public Hashtable getContextProperties()
+ public void setIdleTimeout(long idleTimeout)
{
- return contextProperties;
+ this.poolParams.idleTimeout = idleTimeout;
}
+
+ public class ConnectionManagerDelegate implements ConnectionManager
+ {
+ private static final long serialVersionUID = 1L;
- public void setContextProperties(Hashtable contextProperties)
+ public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo cxRequestInfo) throws ResourceException
+ {
+ return connectionManager.allocateConnection(mcf, cxRequestInfo);
+ }
+ }
+ public void setCachedConnectionManager(CachedConnectionManagerReference reference)
{
- this.contextProperties = contextProperties;
+ this.cachedConnectionManager = reference.getCachedConnectionManager();
}
+ public String getDriverClass()
+ {
+ return this.managedConnectionFactory.getXADataSourceClass();
+ }
+
+ public void setDriverClass(final String driverClass)
+ {
+ this.managedConnectionFactory.setXADataSourceClass(driverClass);
+ }
+ public void setUserName(final String userName)
+ {
+ this.managedConnectionFactory.setUserName(userName);
+ }
+
+ public void setPassword(final String password)
+ {
+ this.managedConnectionFactory.setPassword(password);
+ }
}
More information about the jboss-svn-commits
mailing list