[jboss-cvs] JBoss Messaging SVN: r8275 - in branches/Branch_1_4: integration/EAP4/etc/xmdesc and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 22 22:48:47 EDT 2011


Author: gaohoward
Date: 2011-04-22 22:48:46 -0400 (Fri, 22 Apr 2011)
New Revision: 8275

Modified:
   branches/Branch_1_4/integration/AS5/etc/xmdesc/ServerPeer-xmbean.xml
   branches/Branch_1_4/integration/EAP4/etc/xmdesc/ServerPeer-xmbean.xml
   branches/Branch_1_4/integration/EAP5/etc/xmdesc/ServerPeer-xmbean.xml
   branches/Branch_1_4/src/main/org/jboss/jms/server/ServerPeer.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/tests/src/org/jboss/test/messaging/jms/server/ServerPeerTest.java
Log:
JBMESSAGING-1853



Modified: branches/Branch_1_4/integration/AS5/etc/xmdesc/ServerPeer-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/AS5/etc/xmdesc/ServerPeer-xmbean.xml	2011-04-22 03:30:05 UTC (rev 8274)
+++ branches/Branch_1_4/integration/AS5/etc/xmdesc/ServerPeer-xmbean.xml	2011-04-23 02:48:46 UTC (rev 8275)
@@ -247,6 +247,12 @@
       <type>boolean</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="isCrashServerOnDBFailure" setMethod="setCrashServerOnDBFailure">
+      <description>Whether or not to crash the server if DB failed to work.</description>
+      <name>CrashServerOnDBFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>

Modified: branches/Branch_1_4/integration/EAP4/etc/xmdesc/ServerPeer-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP4/etc/xmdesc/ServerPeer-xmbean.xml	2011-04-22 03:30:05 UTC (rev 8274)
+++ branches/Branch_1_4/integration/EAP4/etc/xmdesc/ServerPeer-xmbean.xml	2011-04-23 02:48:46 UTC (rev 8275)
@@ -248,6 +248,12 @@
       <type>boolean</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="isCrashServerOnDBFailure" setMethod="setCrashServerOnDBFailure">
+      <description>Whether or not to crash the server if DB failed to work.</description>
+      <name>CrashServerOnDBFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>

Modified: branches/Branch_1_4/integration/EAP5/etc/xmdesc/ServerPeer-xmbean.xml
===================================================================
--- branches/Branch_1_4/integration/EAP5/etc/xmdesc/ServerPeer-xmbean.xml	2011-04-22 03:30:05 UTC (rev 8274)
+++ branches/Branch_1_4/integration/EAP5/etc/xmdesc/ServerPeer-xmbean.xml	2011-04-23 02:48:46 UTC (rev 8275)
@@ -253,6 +253,12 @@
       <type>boolean</type>
    </attribute>
 
+   <attribute access="read-write" getMethod="isCrashServerOnDBFailure" setMethod="setCrashServerOnDBFailure">
+      <description>Whether or not to crash the server if DB failed to work.</description>
+      <name>CrashServerOnDBFailure</name>
+      <type>boolean</type>
+   </attribute>
+
    <!-- Managed operations -->
 
    <operation>

Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/ServerPeer.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/ServerPeer.java	2011-04-22 03:30:05 UTC (rev 8274)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/ServerPeer.java	2011-04-23 02:48:46 UTC (rev 8275)
@@ -185,6 +185,8 @@
    private int suckerConnectionRetryInterval = 5000;
 
    private boolean supportsTxAge;
+   
+   private volatile boolean crashServerOnDBFailure;
 
    // wired components
 
@@ -271,6 +273,7 @@
          if (persistenceManager instanceof JDBCPersistenceManager)
          {
          	((JDBCPersistenceManager)persistenceManager).injectNodeID(serverPeerID);
+            ((JDBCPersistenceManager)persistenceManager).setCrashServerOnDBFailure(this.crashServerOnDBFailure);
          }
          else if (persistenceManager instanceof NullPersistenceManager)
          {
@@ -2067,6 +2070,20 @@
       }
    }
 
+   public boolean isCrashServerOnDBFailure()
+   {
+      return crashServerOnDBFailure;
+   }
+   
+   public void setCrashServerOnDBFailure(boolean crashServer)
+   {
+      this.crashServerOnDBFailure = crashServer;
+      if (persistenceManager != null && (persistenceManager instanceof JDBCPersistenceManager))
+      {
+         ((JDBCPersistenceManager)persistenceManager).setCrashServerOnDBFailure(crashServer);
+      }
+   }
+   
    private void initClusterHealthBean()
    {
       if (this.messagingClusterHealthMBeanObjectName != null)

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	2011-04-22 03:30:05 UTC (rev 8274)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java	2011-04-23 02:48:46 UTC (rev 8275)
@@ -111,6 +111,9 @@
    private int retryInterval = 1000;
 
    private boolean retryOnConnectionFailure = false;
+   
+   private volatile boolean crashServerOnDBFailure = false;
+   
    // Constructors --------------------------------------------------
 
    public JDBCPersistenceManager(DataSource ds, TransactionManager tm,
@@ -3449,6 +3452,17 @@
       return supportsTxAge;
    }
 
+   @Override
+   public void handleFatalDBError(String msg) throws Exception
+   {
+      if (crashServerOnDBFailure)
+      {
+         log.error(this + " Crash the server due to fatal DB error: " + msg);
+         Runtime.getRuntime().halt(1853);
+      }
+      super.handleFatalDBError(msg);
+   }
+
    public void updateMessageState(final long channelID, final MessageReference ref, final String c) throws Exception
    {
       class UpdateMessageStateRunner extends JDBCTxRunner2
@@ -3594,4 +3608,9 @@
       }
    }
 
+   public void setCrashServerOnDBFailure(boolean crashServerOnDBFailure)
+   {
+      this.crashServerOnDBFailure = crashServerOnDBFailure;
+   }
+
 }

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	2011-04-22 03:30:05 UTC (rev 8274)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/JDBCSupport.java	2011-04-23 02:48:46 UTC (rev 8275)
@@ -416,7 +416,7 @@
                if ((maxRetry != -1) && (retries == maxRetry))
                {
                   log.error("Retried " + retries + " times reconnection, now giving up", e);
-                  throw new IllegalStateException("Failed to get connection");
+                  handleFatalDBError("Failed to get connection");
                }
 
                if (JMSServerInvocationHandler.isClosing())
@@ -460,7 +460,7 @@
                if ((maxRetry != -1) && (retries == maxRetry))
                {
                   log.error("Retried " + retries + " times reconnection, now giving up", e);
-                  throw new IllegalStateException("Failed to get connection");
+                  handleFatalDBError("Failed to get connection");
                }
 
                if ( JMSServerInvocationHandler.isClosing())
@@ -483,6 +483,12 @@
       return connection;
    }
 
+   public void handleFatalDBError(String errMsg) throws Exception
+   {
+      log.error(this + " Fatal DB error happened. Error " + errMsg);
+      throw new IllegalStateException(errMsg);
+   }
+   
    protected class TransactionWrapper
    {
       private javax.transaction.Transaction oldTx;
@@ -608,7 +614,7 @@
 	            if ((maxRetry != -1) && (tries == maxRetry))
 	            {
 	               log.error("Retried " + tries + " times, now giving up");
-	               throw new IllegalStateException("Failed to excecute transaction");
+	               handleFatalDBError("Failed to execute transaction");
 	            }
                tries++;
 	            log.warn("Trying again after a pause of " + retryInterval + " ms.");
@@ -720,7 +726,7 @@
                if ((maxRetry != -1) && (tries == maxRetry))
                {
                   log.error("Retried " + tries + " times, now giving up");
-                  throw new IllegalStateException("Failed to execute transaction");
+                  handleFatalDBError("Failed to execute transaction");
                }
                tries++;
                log.warn("Trying again after a pause of " + retryInterval + " ms.");

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	2011-04-22 03:30:05 UTC (rev 8274)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/core/impl/postoffice/MessagingPostOffice.java	2011-04-23 02:48:46 UTC (rev 8275)
@@ -1289,6 +1289,16 @@
 		return firstNode;
 	}
 	
+	@Override
+	public void handleFatalDBError(String msg) throws Exception
+	{
+	   if (serverPeer.isCrashServerOnDBFailure())
+	   {
+	      log.error(this + " Crash the server due to fatal DB error: " + msg);
+	      Runtime.getRuntime().halt(1853);
+	   }
+	   super.handleFatalDBError(msg);
+	}
 	
 	//	Testing only
    

Modified: branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/ServerPeerTest.java
===================================================================
--- branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/ServerPeerTest.java	2011-04-22 03:30:05 UTC (rev 8274)
+++ branches/Branch_1_4/tests/src/org/jboss/test/messaging/jms/server/ServerPeerTest.java	2011-04-23 02:48:46 UTC (rev 8275)
@@ -215,6 +215,24 @@
 
       assertEquals(on, defaultExpiry);
    }
+
+   public void testSetGetCrashServerOnDBFailure() throws Exception
+   {
+      if(!ServerManagement.isServerPeerStarted())
+      {
+         ServerManagement.startServerPeer();
+      }
+
+      Boolean defValue = (Boolean)ServerManagement.getAttribute(ServerManagement.getServerPeerObjectName(), "CrashServerOnDBFailure");
+      
+      assertFalse(defValue);
+      
+      ServerManagement.setAttribute(ServerManagement.getServerPeerObjectName(), "CrashServerOnDBFailure", "true");
+      
+      Boolean newValue = (Boolean)ServerManagement.getAttribute(ServerManagement.getServerPeerObjectName(), "CrashServerOnDBFailure");
+
+      assertTrue(newValue);
+   }
    
    public void testRetrievePreparedTransactions() throws Exception
    {



More information about the jboss-cvs-commits mailing list