[jboss-svn-commits] JBL Code SVN: r24574 - labs/jbosstm/branches/JBOSSTS_4_2_3_GA_CP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 7 07:07:19 EST 2009
Author: jhalliday
Date: 2009-01-07 07:07:19 -0500 (Wed, 07 Jan 2009)
New Revision: 24574
Modified:
labs/jbosstm/branches/JBOSSTS_4_2_3_GA_CP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java
Log:
Backported AppServerJDBCXARecovery.java robustness enhancements from the SP branch to CP. JBTM-441 and JBTM-442
Modified: labs/jbosstm/branches/JBOSSTS_4_2_3_GA_CP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_2_3_GA_CP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java 2009-01-07 11:39:55 UTC (rev 24573)
+++ labs/jbosstm/branches/JBOSSTS_4_2_3_GA_CP/atsintegration/classes/com/arjuna/ats/internal/jbossatx/jta/AppServerJDBCXARecovery.java 2009-01-07 12:07:19 UTC (rev 24574)
@@ -30,7 +30,10 @@
import javax.sql.XAConnection;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
+import javax.management.MBeanException;
+import javax.management.InstanceNotFoundException;
import java.sql.SQLException;
+import java.sql.Connection;
import java.util.Properties;
import java.util.Iterator;
import java.io.InputStream;
@@ -111,6 +114,10 @@
{
createConnection();
+ if (_connection == null) {
+ throw new SQLException("The data source named [" + _dataSourceId + "] is not deployed.");
+ }
+
return _connection.getXAResource();
}
@@ -165,6 +172,7 @@
try {
_dataSource = getXADataSource(className, properties);
+ _supportsIsValidMethod = true; // assume it does; we'll lazily check the first time we try to connect
} catch(Exception e) {
_dataSource = null;
log.error("AppServerJDBCXARecovery.createDataSource got exception during getXADataSource call: "+e.toString(), e);
@@ -172,6 +180,21 @@
}
}
}
+ catch (MBeanException mbe)
+ {
+ if (mbe.getTargetException() instanceof InstanceNotFoundException)
+ {
+ log.warn("AppServerJDBCXARecovery.createDataSource(name="+_dataSourceId+"): InstanceNotFound. Datasource not deployed, or wrong name?");
+
+ // this is an expected condition when the data source is not yet deployed
+ // just ignore this for now, the next time around, we try again to see if its deployed yet
+ return;
+ } else {
+ log.error("AppServerJDBCXARecovery.createDataSource(name="+_dataSourceId+") got exception " + mbe.toString(), mbe);
+ }
+
+ throw new SQLException(mbe.toString());
+ }
catch (SQLException ex)
{
log.error("AppServerJDBCXARecovery.createDataSource got exception "+ex.toString(), ex);
@@ -196,12 +219,45 @@
try
{
if (_dataSource == null)
+ {
createDataSource();
+ // if we still don't have it, its because the data source isn't deployed yet
+ if (_dataSource == null) {
+ return;
+ }
+ }
- if (_connection == null)
- {
+ Boolean isConnectionValid;
+ try {
+ if (_connection != null && _supportsIsValidMethod) {
+ Connection connection = _connection.getConnection();
+ Method method = connection.getClass().getMethod("isValid", Integer.class);
+ isConnectionValid = (Boolean) method.invoke(connection, Integer.valueOf(5));
+ } else {
+ isConnectionValid = Boolean.FALSE;
+ }
+ } catch (NoSuchMethodException nsme) {
+ isConnectionValid = Boolean.FALSE;
+ _supportsIsValidMethod = false;
+ log.debug("XA datasource does not support isValid method - connection will always be recreated");
+ } catch (Throwable t) {
+ isConnectionValid = Boolean.FALSE;
+ log.debug("XA connection is invalid - will recreate a new one. Cause: " + t);
+ }
+
+ if (!isConnectionValid.booleanValue()) {
+ if (_connection != null) {
+ try {
+ _connection.close(); // just attempt to clean up anything that we can
+ } catch (Throwable t) {
+ } finally {
+ _connection = null;
+ }
+ }
+
_connection = _dataSource.getXAConnection();
_connection.addConnectionEventListener(_connectionEventListener);
+ log.debug("Created new XAConnection");
}
}
catch (SQLException ex)
@@ -288,6 +344,7 @@
return xads;
}
+ private boolean _supportsIsValidMethod;
private XAConnection _connection;
private XADataSource _dataSource;
private LocalConnectionEventListener _connectionEventListener;
More information about the jboss-svn-commits
mailing list