[Jboss-cvs] JBossAS SVN: r57044 - in branches/Branch_4_0/messaging/src/main/org/jboss/mq: pm/jdbc2 sm/jdbc
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Sep 21 01:07:40 EDT 2006
Author: adrian at jboss.org
Date: 2006-09-21 01:07:29 -0400 (Thu, 21 Sep 2006)
New Revision: 57044
Modified:
branches/Branch_4_0/messaging/src/main/org/jboss/mq/pm/jdbc2/PersistenceManager.java
branches/Branch_4_0/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java
branches/Branch_4_0/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManagerMBean.java
Log:
[JBAS-3620] - Avoid JBossMQ not starting when the database is in
a flakey state.
Modified: branches/Branch_4_0/messaging/src/main/org/jboss/mq/pm/jdbc2/PersistenceManager.java
===================================================================
--- branches/Branch_4_0/messaging/src/main/org/jboss/mq/pm/jdbc2/PersistenceManager.java 2006-09-21 05:05:53 UTC (rev 57043)
+++ branches/Branch_4_0/messaging/src/main/org/jboss/mq/pm/jdbc2/PersistenceManager.java 2006-09-21 05:07:29 UTC (rev 57044)
@@ -1791,7 +1791,14 @@
initializeFields();
log.debug("Creating Schema");
- createSchema();
+ try
+ {
+ createSchema();
+ }
+ catch (Exception e)
+ {
+ log.warn("Error creating schema", e);
+ }
log.debug("Resolving uncommited TXS");
Throwable error = null;
Modified: branches/Branch_4_0/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java
===================================================================
--- branches/Branch_4_0/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java 2006-09-21 05:05:53 UTC (rev 57043)
+++ branches/Branch_4_0/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java 2006-09-21 05:07:29 UTC (rev 57044)
@@ -76,6 +76,9 @@
/** The data source */
protected DataSource dataSource;
+ /** The connection retries */
+ protected int connectionRetryAttempts = 5;
+
/** Whether there is a security manager */
private boolean hasSecurityManager = true;
@@ -175,6 +178,16 @@
}
}
+ public void setConnectionRetryAttempts(int value)
+ {
+ this.connectionRetryAttempts = value;
+ }
+
+ public int getConnectionRetryAttempts()
+ {
+ return this.connectionRetryAttempts;
+ }
+
protected DurableSubscription getDurableSubscription(DurableSubscriptionID sub) throws JMSException
{
JDBCSession session = new JDBCSession();
@@ -375,7 +388,14 @@
ctx.close();
}
- initDB();
+ try
+ {
+ initDB();
+ }
+ catch (Exception e)
+ {
+ log.warn("Error initialising state manager db", e);
+ }
}
protected void initDB() throws Exception
@@ -495,7 +515,7 @@
try
{
// Retrieve a connection
- connection = dataSource.getConnection();
+ connection = getConnection();
}
catch (Throwable t)
{
@@ -630,5 +650,62 @@
}
}
}
+
+ /**
+ * Gets a connection from the datasource, retrying as needed. This was
+ * implemented because in some minimal configurations (i.e. little logging
+ * and few services) the database wasn't ready when we tried to get a
+ * connection. We, therefore, implement a retry loop wich is controled
+ * by the ConnectionRetryAttempts attribute. Submitted by terry at amicas.com
+ *
+ * @exception SQLException if an error occurs.
+ */
+ protected Connection getConnection() throws SQLException
+ {
+ int attempts = connectionRetryAttempts;
+ int attemptCount = 0;
+ SQLException sqlException = null;
+ while (attempts-- > 0)
+ {
+ if (++attemptCount > 1)
+ {
+ log.debug("Retrying connection: attempt # " + attemptCount);
+ }
+ try
+ {
+ sqlException = null;
+ return dataSource.getConnection();
+ }
+ catch (SQLException exception)
+ {
+ log.debug("Connection attempt # " + attemptCount + " failed with SQLException", exception);
+ sqlException = exception;
+ }
+ finally
+ {
+ if (sqlException == null && attemptCount > 1)
+ {
+ log.debug("Connection succeeded on attempt # " + attemptCount);
+ }
+ }
+
+ if (attempts > 0)
+ {
+ try
+ {
+ Thread.sleep(1500);
+ }
+ catch (InterruptedException interruptedException)
+ {
+ break;
+ }
+ }
+ }
+ if (sqlException != null)
+ {
+ throw sqlException;
+ }
+ throw new SQLException("connection attempt interrupted");
+ }
}
}
Modified: branches/Branch_4_0/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManagerMBean.java
===================================================================
--- branches/Branch_4_0/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManagerMBean.java 2006-09-21 05:05:53 UTC (rev 57043)
+++ branches/Branch_4_0/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManagerMBean.java 2006-09-21 05:07:29 UTC (rev 57044)
@@ -76,4 +76,18 @@
* @param sqlProperties sqlProperties to set
*/
void setSqlProperties(String value);
+
+ /**
+ * Sets the ConnectionRetryAttempts.
+ *
+ * @param connectionRetryAttempts value
+ */
+ void setConnectionRetryAttempts(int value);
+
+ /**
+ * Gets the ConnectionRetryAttempts.
+ *
+ * @return Returns a ConnectionRetryAttempt value
+ */
+ int getConnectionRetryAttempts();
}
More information about the jboss-cvs-commits
mailing list