[jboss-cvs] JBoss Messaging SVN: r8160 - in branches/Branch_1_4: integration/AS5/etc/xmdesc and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 3 23:00:35 EST 2011


Author: gaohoward
Date: 2011-01-03 23:00:34 -0500 (Mon, 03 Jan 2011)
New Revision: 8160

Modified:
   branches/Branch_1_4/docs/userguide/en/modules/configuration.xml
   branches/Branch_1_4/integration/AS5/etc/xmdesc/JDBCPersistenceManager-xmbean.xml
   branches/Branch_1_4/integration/AS5/etc/xmdesc/JMSUserManager-xmbean.xml
   branches/Branch_1_4/integration/AS5/etc/xmdesc/MessagingPostOffice-xmbean.xml
   branches/Branch_1_4/integration/EAP4/etc/xmdesc/JDBCPersistenceManager-xmbean.xml
   branches/Branch_1_4/integration/EAP4/etc/xmdesc/JMSUserManager-xmbean.xml
   branches/Branch_1_4/integration/EAP4/etc/xmdesc/MessagingPostOffice-xmbean.xml
   branches/Branch_1_4/integration/EAP5/etc/xmdesc/JDBCPersistenceManager-xmbean.xml
   branches/Branch_1_4/integration/EAP5/etc/xmdesc/JMSUserManager-xmbean.xml
   branches/Branch_1_4/integration/EAP5/etc/xmdesc/MessagingPostOffice-xmbean.xml
   branches/Branch_1_4/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManager.java
   branches/Branch_1_4/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManagerService.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCSupport.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/JDBCPersistenceManagerService.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/JDBCServiceSupport.java
   branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/MessagingPostOfficeService.java
   branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java
Log:
JBMESSAGING-1838


Modified: branches/Branch_1_4/docs/userguide/en/modules/configuration.xml
===================================================================
--- branches/Branch_1_4/docs/userguide/en/modules/configuration.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/docs/userguide/en/modules/configuration.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -1002,6 +1002,30 @@
         <ulink
         url="http://wiki.jboss.org/wiki/Wiki.jsp?page=JGroups">http://wiki.jboss.org/wiki/Wiki.jsp?page=JGroups</ulink>.</para>
       </section>
+
+      <section id="conf.postoffice.attributes.maxretry">
+        <title>MaxRetry</title>
+
+        <para>The maximum number of retries when any Database operation fails.
+        Default value is 25. Setting a value of -1 means retry forever.</para>
+      </section>
+
+      <section id="conf.postoffice.attributes.retryinterval">
+        <title>RetryInterval</title>
+
+        <para>The interval (in milliseconds) between two DB retries. Default value
+        is 1000 (1 second).</para>
+
+        <para>This attribute should be used in combination with MaxRetry.</para>
+      </section>
+
+      <section id="conf.postoffice.attributes.retryonconnectionfailure">
+        <title>RetryOnConnectionFailure</title>
+
+        <para>It controls whether or not to retry connection creation on a DataSource
+        if it is failed to get a connection. Default value is false.</para>
+      </section>
+
     </section>
   </section>
 
@@ -1259,6 +1283,29 @@
         <literal>UseNDBFailoverStrategy</literal> attribute is set to
         <literal>false</literal></para>
       </section>
+
+      <section id="conf.persistencemanager.attributes.maxretry">
+        <title>MaxRetry</title>
+
+        <para>The maximum number of retries when any Database operation fails.
+        Default value is 25. Setting a value of -1 means retry forever.</para>
+      </section>
+
+      <section id="conf.persistencemanager.attributes.retryinterval">
+        <title>RetryInterval</title>
+
+        <para>The interval (in milliseconds) between two DB retries. Default value
+        is 1000 (1 second).</para>
+
+        <para>This attribute should be used in combination with MaxRetry.</para>
+      </section>
+
+      <section id="conf.persistencemanager.attributes.retryonconnectionfailure">
+        <title>RetryOnConnectionFailure</title>
+
+        <para>It controls whether or not to retry connection creation on a DataSource
+        if it is failed to get a connection. Default value is false.</para>
+      </section>
     </section>
 
     <!-- end conf.persistencemanager.attributes -->
@@ -1339,6 +1386,29 @@
         to be inserted must be specified with property names starting with
         <literal>POPULATE.TABLES</literal> as in the above example.</para>
       </section>
+
+      <section id="conf.jmsusermanager.attributes.maxretry">
+        <title>MaxRetry</title>
+
+        <para>The maximum number of retries when any Database operation fails.
+        Default value is 25. Setting a value of -1 means retry forever.</para>
+      </section>
+
+      <section id="conf.jmsusermanager.attributes.retryinterval">
+        <title>RetryInterval</title>
+
+        <para>The interval (in milliseconds) between two DB retries. Default value
+        is 1000 (1 second).</para>
+
+        <para>This attribute should be used in combination with MaxRetry.</para>
+      </section>
+
+      <section id="conf.jmsusermanager.attributes.retryonconnectionfailure">
+        <title>RetryOnConnectionFailure</title>
+
+        <para>It controls whether or not to retry connection creation on a DataSource
+        if it is failed to get a connection. Default value is false.</para>
+      </section>
     </section>
 
     <!-- end conf.jmsusermanager.attributes -->

Modified: branches/Branch_1_4/integration/AS5/etc/xmdesc/JDBCPersistenceManager-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/AS5/etc/xmdesc/JDBCPersistenceManager-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/AS5/etc/xmdesc/JDBCPersistenceManager-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -96,6 +96,24 @@
       <type>int</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>

Modified: branches/Branch_1_4/integration/AS5/etc/xmdesc/JMSUserManager-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/AS5/etc/xmdesc/JMSUserManager-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/AS5/etc/xmdesc/JMSUserManager-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -41,6 +41,24 @@
       <type>boolean</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>
@@ -63,4 +81,4 @@
       <name>destroy</name>
    </operation>   
 
-</mbean>
\ No newline at end of file
+</mbean>

Modified: branches/Branch_1_4/integration/AS5/etc/xmdesc/MessagingPostOffice-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/AS5/etc/xmdesc/MessagingPostOffice-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/AS5/etc/xmdesc/MessagingPostOffice-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -137,6 +137,24 @@
       <type>java.util.Set</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>
@@ -159,4 +177,4 @@
       <name>destroy</name>
    </operation>
      
-</mbean>
\ No newline at end of file
+</mbean>

Modified: branches/Branch_1_4/integration/EAP4/etc/xmdesc/JDBCPersistenceManager-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP4/etc/xmdesc/JDBCPersistenceManager-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/EAP4/etc/xmdesc/JDBCPersistenceManager-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -95,6 +95,24 @@
       <type>int</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>

Modified: branches/Branch_1_4/integration/EAP4/etc/xmdesc/JMSUserManager-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP4/etc/xmdesc/JMSUserManager-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/EAP4/etc/xmdesc/JMSUserManager-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -41,6 +41,24 @@
       <type>boolean</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>
@@ -63,4 +81,4 @@
       <name>destroy</name>
    </operation>   
 
-</mbean>
\ No newline at end of file
+</mbean>

Modified: branches/Branch_1_4/integration/EAP4/etc/xmdesc/MessagingPostOffice-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP4/etc/xmdesc/MessagingPostOffice-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/EAP4/etc/xmdesc/MessagingPostOffice-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -137,6 +137,24 @@
       <type>java.util.Set</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>
@@ -159,4 +177,4 @@
       <name>destroy</name>
    </operation>
      
-</mbean>
\ No newline at end of file
+</mbean>

Modified: branches/Branch_1_4/integration/EAP5/etc/xmdesc/JDBCPersistenceManager-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP5/etc/xmdesc/JDBCPersistenceManager-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/EAP5/etc/xmdesc/JDBCPersistenceManager-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -96,6 +96,24 @@
       <type>int</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>

Modified: branches/Branch_1_4/integration/EAP5/etc/xmdesc/JMSUserManager-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP5/etc/xmdesc/JMSUserManager-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/EAP5/etc/xmdesc/JMSUserManager-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -41,6 +41,24 @@
       <type>boolean</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>
@@ -63,4 +81,4 @@
       <name>destroy</name>
    </operation>   
 
-</mbean>
\ No newline at end of file
+</mbean>

Modified: branches/Branch_1_4/integration/EAP5/etc/xmdesc/MessagingPostOffice-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP5/etc/xmdesc/MessagingPostOffice-xmbean.xml	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/integration/EAP5/etc/xmdesc/MessagingPostOffice-xmbean.xml	2011-01-04 04:00:34 UTC (rev 8160)
@@ -130,13 +130,31 @@
       <name>FailoverOnNodeLeave</name>
       <type>boolean</type>
    </attribute>   
-   
+
    <attribute access="read-only" getMethod="getNodeIDView">
       <description>Get the set of nodes in the cluster</description>
       <name>NodeIDView</name>
       <type>java.util.Set</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="getMaxRetry" setMethod="setMaxRetry">
+      <description>Maximal retry times on DataSource failures, default 25</description>
+      <name>MaxRetry</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryInterval" setMethod="setRetryInterval">
+      <description>Retry interval (in milliseconds), default 1000 (1 sec)</description>
+      <name>RetryInterval</name>
+      <type>int</type>
+   </attribute>
+
+   <attribute access="read-write" getMethod="getRetryOnConnectionFailure" setMethod="setRetryOnConnectionFailure">
+      <description>If retry on connection failure, default false</description>
+      <name>RetryOnConnectionFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>
@@ -159,4 +177,4 @@
       <name>destroy</name>
    </operation>
      
-</mbean>
\ No newline at end of file
+</mbean>

Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManager.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManager.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManager.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -63,6 +63,13 @@
    {
       super(ds, tm, sqlProperties, createTablesOnStartup);
    }
+   
+   public JDBCJMSUserManager(DataSource ds, TransactionManager tm, Properties sqlProperties,
+                             boolean createTablesOnStartup, int maxRetry,
+                             int retryInterval, boolean retryOnConnectionFailure)
+   {
+      super(ds, tm, sqlProperties, createTablesOnStartup, maxRetry, retryInterval, retryOnConnectionFailure);
+   }
       
    // JDBCSupport overrides ----------------------------
    
@@ -123,7 +130,7 @@
       
       try
       {
-         conn = ds.getConnection();
+         conn = getConnectionWithRetry();
 
          ps = conn.prepareStatement(getSQLStatement("SELECT_PRECONF_CLIENTID"));
          
@@ -194,7 +201,7 @@
                
                tx = new TransactionWrapper();
                
-               conn = ds.getConnection();
+               conn = getConnectionWithRetry();
                
                st = conn.createStatement();
                

Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManagerService.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManagerService.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/plugin/JDBCJMSUserManagerService.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -73,7 +73,8 @@
       {  
          TransactionManager tm = getTransactionManagerReference();
          
-         userManager = new JDBCJMSUserManager(ds, tm, sqlProperties, createTablesOnStartup);
+         userManager = new JDBCJMSUserManager(ds, tm, sqlProperties, createTablesOnStartup, maxRetry,
+                                              retryInterval, retryOnConnectionFailure);
          
          userManager.start();
          

Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -105,7 +105,12 @@
    private final int idCacheSize;
    
    private boolean supportsTxAge;
+   
+   private int maxRetry = 25;
+   
+   private int retryInterval = 1000;
 
+   private boolean retryOnConnectionFailure = false;
    // Constructors --------------------------------------------------
 
    public JDBCPersistenceManager(DataSource ds, TransactionManager tm,
@@ -143,7 +148,34 @@
       this (ds, tm, sqlProperties, createTablesOnStartup, usingBatchUpdates, usingBinaryStream, usingTrailingByte,
             maxParams, supportsBlobSelect, supportsSetNullOnBlobs, false, false, 0);
    }
+   
+   public JDBCPersistenceManager(DataSource ds, TransactionManager tm,
+                                 Properties sqlProperties, boolean createTablesOnStartup,
+                                 boolean usingBatchUpdates, boolean usingBinaryStream,
+                                 boolean usingTrailingByte, int maxParams, boolean supportsBlobSelect, boolean supportsSetNullOnBlobs,
+                                 boolean detectDuplicates, boolean useNDBFailoverStrategy, int idCacheSize,
+                                 int maxRetry, int retryInterval, boolean retryOnConnectionFailure)
+   {
+      super(ds, tm, sqlProperties, createTablesOnStartup, useNDBFailoverStrategy, maxRetry, retryInterval, retryOnConnectionFailure);
 
+      // usingBatchUpdates is currently ignored due to sketchy support from
+      // databases
+
+      this.usingBinaryStream = usingBinaryStream;
+
+      this.usingTrailingByte = usingTrailingByte;
+
+      this.maxParams = maxParams;
+
+      this.supportsBlobSelect = supportsBlobSelect;
+      
+      this.supportsSetNullOnBlobs = supportsSetNullOnBlobs;
+
+      this.detectDuplicates = detectDuplicates;
+
+      this.idCacheSize = idCacheSize;      
+   }
+
    // MessagingComponent overrides ---------------------------------
 
    public void start() throws Exception
@@ -158,7 +190,7 @@
 
       try
       {
-         conn = ds.getConnection();
+         conn = getConnectionWithRetry();
          // JBossMessaging requires transaction isolation of READ_COMMITTED
          // Any looser isolation level and we cannot maintain consistency for
          // paging (HSQL)
@@ -333,7 +365,7 @@
       {
          List<PreparedTxInfo> transactions = new ArrayList<PreparedTxInfo>();
 
-         conn = ds.getConnection();
+         conn = getConnectionWithRetry();
 
          if (supportsTxAge)
          {
@@ -907,7 +939,7 @@
 
       try
       {
-         conn = ds.getConnection();
+         conn = getConnectionWithRetry();
 
          ps = conn.prepareStatement(getSQLStatement("LOAD_PAGED_REFS"));
 
@@ -977,7 +1009,7 @@
 
       try
       {
-         conn = ds.getConnection();
+         conn = getConnectionWithRetry();
 
          // First we get the values for min() and max() page order
          ps = conn.prepareStatement(getSQLStatement("SELECT_MIN_MAX_PAGE_ORD"));
@@ -1870,7 +1902,7 @@
 
       try
       {
-         conn = ds.getConnection();
+         conn = getConnectionWithRetry();
 
          st = conn.prepareStatement(getSQLStatement("LOAD_ID_CACHE"));
 
@@ -3077,7 +3109,7 @@
 
       try
       {
-         conn = ds.getConnection();
+         conn = getConnectionWithRetry();
 
          ps = conn.prepareStatement(sqlQuery);
 

Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCSupport.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCSupport.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCSupport.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -63,6 +63,12 @@
        
    protected boolean createTablesOnStartup = true;
       
+   private int maxRetry = 25;
+   
+   private int retryInterval = 1000;
+
+   private boolean retryOnConnectionFailure = false;
+
    public JDBCSupport()
    {
       defaultDMLStatements = new LinkedHashMap();
@@ -89,13 +95,45 @@
       this.createTablesOnStartup = createTablesOnStartup;
    }
 
-    public JDBCSupport(DataSource ds, TransactionManager tm, Properties sqlProperties,
+   public JDBCSupport(DataSource ds, TransactionManager tm, Properties sqlProperties,
                       boolean createTablesOnStartup, boolean useNDBFailoverStrategy)
    {
       this(ds, tm, sqlProperties, createTablesOnStartup);
       this.useNDBFailoverStrategy = useNDBFailoverStrategy;
    }
 
+   public JDBCSupport(DataSource ds, TransactionManager tm, Properties sqlProperties,
+                      boolean createTablesOnStartup, boolean useNDBFailoverStrategy,
+                      int maxRetry, int retryInterval, boolean retryOnConnectionFailure)
+   {
+      this(ds, tm, sqlProperties, createTablesOnStartup);
+      this.useNDBFailoverStrategy = useNDBFailoverStrategy;
+      this.maxRetry = maxRetry;
+      this.retryInterval = retryInterval;
+      this.retryOnConnectionFailure = retryOnConnectionFailure;
+   }
+   
+   public JDBCSupport(DataSource ds, TransactionManager tm, Properties sqlProperties,
+                      boolean createTablesOnStartup, int maxRetry, int retryInterval,
+                      boolean retryOnConnectionFailure)
+   {
+      this();
+      
+      this.ds = ds;
+      
+      this.tm = tm;
+      
+      if (sqlProperties != null)
+      {
+         this.sqlProperties = sqlProperties;
+      }
+      
+      this.createTablesOnStartup = createTablesOnStartup;
+      this.maxRetry = maxRetry;
+      this.retryInterval = retryInterval;
+      this.retryOnConnectionFailure = retryOnConnectionFailure;
+   }
+
    // MessagingComponent overrides ---------------------------------
    
    public void start() throws Exception
@@ -284,7 +322,7 @@
                   
          try
          {                        
-            conn = ds.getConnection();
+            conn = getConnectionWithRetry();
                         
             String statementName = (String)i.next();
              
@@ -325,6 +363,111 @@
    
    // Innner classes ---------------------------------------------------------
    
+   public void setMaxRetry(int maxRetry)
+   {
+      this.maxRetry = maxRetry;
+   }
+
+   public int getMaxRetry()
+   {
+      return maxRetry;
+   }
+
+   public void setRetryInterval(int retryInterval)
+   {
+      this.retryInterval = retryInterval;
+   }
+
+   public int getRetryInterval()
+   {
+      return retryInterval;
+   }
+
+   public void setRetryOnConnectionFailure(boolean retryOnConnectionFailure)
+   {
+      this.retryOnConnectionFailure = retryOnConnectionFailure;
+   }
+
+   public boolean getRetryOnConnectionFailure()
+   {
+      return retryOnConnectionFailure;
+   }
+
+   public Connection getConnectionWithRetry(boolean autoCommit) throws Exception
+   {
+      Connection connection = null;
+      int retries = 0;
+      while (connection == null)
+      {
+         try
+         {
+            connection = ds.getConnection();
+            connection.setAutoCommit(autoCommit);
+         }
+         catch (Exception e)
+         {
+            if (trace)
+            {
+               log.trace("Failure in getting connection", e);
+            }
+            if (retryOnConnectionFailure)
+            {
+               if ((maxRetry != -1) && (retries == maxRetry))
+               {
+                  log.error("Retried " + retries + " times reconnection, now giving up", e);
+                  throw new IllegalStateException("Failed to get connection");
+               }
+               retries++;
+               log.warn("Trying reconnection again after a pause of " + retryInterval + " ms.");
+               
+               Thread.sleep(retryInterval);
+            }
+            else
+            {
+               throw e;
+            }
+         }
+      }
+      return connection;
+   }
+   
+   public Connection getConnectionWithRetry() throws Exception
+   {
+      Connection connection = null;
+      int retries = 0;
+      while (connection == null)
+      {
+         try
+         {
+            connection = ds.getConnection();
+         }
+         catch (Exception e)
+         {
+            if (trace)
+            {
+               log.trace("Failure in getting connection", e);
+            }
+            if (retryOnConnectionFailure)
+            {
+               if ((maxRetry != -1) && (retries == maxRetry))
+               {
+                  log.error("Retried " + retries + " times reconnection, now giving up", e);
+                  throw new IllegalStateException("Failed to get connection");
+               }
+               retries++;
+               log.warn("Trying reconnection again after a pause of " + retryInterval + " ms.");
+
+               Thread.sleep(retryInterval);
+            }
+            else
+            {
+               throw e;
+            }
+         }
+      }
+      return connection;
+   }
+
    protected class TransactionWrapper
    {
       private javax.transaction.Transaction oldTx;
@@ -377,8 +520,6 @@
 
    protected abstract class JDBCTxRunner<T>
    {
-   	private static final int MAX_TRIES = 25;
-
    	protected Connection conn;
 
       private TransactionWrapper wrap;
@@ -389,7 +530,7 @@
 
 	      try
 	      {
-	         conn = ds.getConnection();
+	         conn = getConnectionWithRetry();
 
 	         return doTransaction();
 	      }
@@ -425,15 +566,15 @@
 	         {
   	            log.warn("SQLException caught, SQLState " + e.getSQLState() + " code:" + e.getErrorCode() + "- assuming deadlock detected, try:" + (tries + 1), e);
 
-	            tries++;
-	            if (tries == MAX_TRIES)
+	            if ((maxRetry != -1) && (tries == maxRetry))
 	            {
 	               log.error("Retried " + tries + " times, now giving up");
 	               throw new IllegalStateException("Failed to excecute transaction");
 	            }
-	            log.warn("Trying again after a pause");
-	            //Now we wait for a random amount of time to minimise risk of deadlock
-	            Thread.sleep((long)(Math.random() * 500));
+               tries++;
+	            log.warn("Trying again after a pause of " + retryInterval + " ms.");
+
+	            Thread.sleep(retryInterval);
 	         }
 	      }
 		}
@@ -444,8 +585,6 @@
    
    protected abstract class JDBCTxRunner2<T>
    {
-      private static final int MAX_TRIES = 25;
-
       protected Connection conn;
       
       private boolean getConnectionFailed;
@@ -460,9 +599,7 @@
          {
             try
             {
-               conn = ds.getConnection();
-            
-               conn.setAutoCommit(false);
+               conn = getConnectionWithRetry(false);
             }
             catch (Exception e)
             {
@@ -537,15 +674,15 @@
                }
                log.warn("SQLException caught, SQLState " + e.getSQLState() + " code:" + e.getErrorCode() + "- assuming deadlock detected, try:" + (tries + 1), e);
 
-               tries++;
-               if (tries == MAX_TRIES)
+               if ((maxRetry != -1) && (tries == maxRetry))
                {
                   log.error("Retried " + tries + " times, now giving up");
                   throw new IllegalStateException("Failed to execute transaction");
                }
-               log.warn("Trying again after a pause");
-               //Now we wait for a random amount of time to minimise risk of deadlock
-               Thread.sleep((long)(Math.random() * 500));
+               tries++;
+               log.warn("Trying again after a pause of " + retryInterval + " ms.");
+
+               Thread.sleep((long)(retryInterval));
             }
          }
       }

Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -273,10 +273,13 @@
                               FilterFactory filterFactory,
                               ConditionFactory conditionFactory,
                               IDManager channelIDManager,
-                              ClusterNotifier clusterNotifier)
+                              ClusterNotifier clusterNotifier,
+                              int maxRetry,
+                              int retryInterval,
+                              boolean retryOnConnectionFailure)
       throws Exception
    {
-   	super (ds, tm, sqlProperties, createTablesOnStartup);
+   	super (ds, tm, sqlProperties, createTablesOnStartup, maxRetry, retryInterval, retryOnConnectionFailure);
 
       this.thisNodeID = nodeId;
       
@@ -324,11 +327,14 @@
                               long stateTimeout, long castTimeout,
                               boolean supportsFailover,
                               int maxConcurrentReplications,
-                              boolean failoverOnNodeLeave)
+                              boolean failoverOnNodeLeave,
+                              int maxRetry,
+                              int retryInterval,
+                              boolean retryOnConnectionFailure)
       throws Exception
    {
    	this(ds, tm, sqlProperties, createTablesOnStartup, nodeId, officeName, ms, pm, tr,
-   		  filterFactory, conditionFactory, channelIDManager, clusterNotifier);
+   		  filterFactory, conditionFactory, channelIDManager, clusterNotifier, maxRetry, retryInterval, retryOnConnectionFailure);
      
       this.clustered = true;
       

Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/JDBCPersistenceManagerService.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/JDBCPersistenceManagerService.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/JDBCPersistenceManagerService.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -95,7 +95,8 @@
             new JDBCPersistenceManager(ds, tm, sqlProperties,
                                        createTablesOnStartup, usingBatchUpdates,
                                        usingBinaryStream, usingTrailingByte, maxParams,
-                                       supportsBlobOnSelect, supportsSetNullOnBlobs, detectDuplicates, useNDBFailoverStrategy, idCacheSize);
+                                       supportsBlobOnSelect, supportsSetNullOnBlobs, detectDuplicates, useNDBFailoverStrategy, idCacheSize,
+                                       maxRetry, retryInterval, retryOnConnectionFailure);
 
          persistenceManager.start();
 

Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/JDBCServiceSupport.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/JDBCServiceSupport.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/JDBCServiceSupport.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -60,6 +60,10 @@
    private String dataSourceJNDIName;
    private ObjectName tmObjectName;
    private TransactionManager tm;
+   
+   protected int maxRetry = 25;
+   protected int retryInterval = 1000;
+   protected boolean retryOnConnectionFailure = false;
 
    // Constructors ---------------------------------------------------------------------------------
 
@@ -160,7 +164,37 @@
    {
       createTablesOnStartup = b;
    }
+   
+   public void setMaxRetry(int maxRetry)
+   {
+      this.maxRetry = maxRetry;
+   }
 
+   public int getMaxRetry()
+   {
+      return maxRetry;
+   }
+
+   public void setRetryInterval(int retryInterval)
+   {
+      this.retryInterval = retryInterval;
+   }
+
+   public int getRetryInterval()
+   {
+      return retryInterval;
+   }
+
+   public void setRetryOnConnectionFailure(boolean retryOnConnectionFailure)
+   {
+      this.retryOnConnectionFailure = retryOnConnectionFailure;
+   }
+
+   public boolean getRetryOnConnectionFailure()
+   {
+      return retryOnConnectionFailure;
+   }
+
    // Public ---------------------------------------------------------------------------------------
 
    // Package protected ----------------------------------------------------------------------------

Modified: branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/MessagingPostOfficeService.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/MessagingPostOfficeService.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/jmx/MessagingPostOfficeService.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -447,7 +447,10 @@
 	                                               stateTimeout, castTimeout,
                                                   serverPeer.isSupportsFailover(),
                                                   maxConcurrentReplications,
-                                                  failoverOnNodeLeave);
+                                                  failoverOnNodeLeave,
+                                                  maxRetry,
+                                                  retryInterval,
+                                                  retryOnConnectionFailure);
          }
          else
          {
@@ -456,7 +459,10 @@
 											                 nodeId, officeName, ms,
 											                 pm,
 											                 tr, ff, cf, idManager,
-											                 clusterNotifier);
+											                 clusterNotifier,
+											                 maxRetry,
+											                 retryInterval,
+											                 retryOnConnectionFailure);
          }
 
          postOffice.start();

Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java	2010-12-28 00:40:00 UTC (rev 8159)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/core/PostOfficeTestBase.java	2011-01-04 04:00:34 UTC (rev 8160)
@@ -44,9 +44,7 @@
 import org.jboss.messaging.core.impl.tx.TransactionRepository;
 import org.jboss.test.messaging.MessagingTestCase;
 import org.jboss.test.messaging.core.postoffice.ClusteredPersistenceServiceConfigFileJChannelFactory;
-import org.jboss.test.messaging.tools.container.ServiceConfigHelper;
 import org.jboss.test.messaging.tools.container.ServiceContainer;
-import org.jboss.test.messaging.tools.jboss.MBeanConfigurationElement;
 import org.jboss.test.messaging.util.CoreMessageFactory;
 
 /**
@@ -95,7 +93,7 @@
                                  sc.getPostOfficeSQLProperties(), true, nodeID,
                                  "Clustered", ms, pm, tr, ff, cf, idm, cn,
                                  groupName, jChannelFactory,
-                                 stateTimeout, castTimeout, true, 100, false);
+                                 stateTimeout, castTimeout, true, 100, false, 25, 1000, false);
 
       postOffice.start();
 
@@ -114,7 +112,7 @@
       MessagingPostOffice postOffice =
          new MessagingPostOffice(sc.getDataSource(), sc.getTransactionManager(),
                                  sc.getPostOfficeSQLProperties(),
-                                 true, 1, "NonClustered", ms, pm, tr, ff, cf, idm, cn);
+                                 true, 1, "NonClustered", ms, pm, tr, ff, cf, idm, cn, 25, 1000, false);
 
       postOffice.start();
 



More information about the jboss-cvs-commits mailing list