You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2009/06/10 16:59:03 UTC

svn commit: r783384 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/store/kahadb/MessageDatabase.java test/java/org/apache/activemq/store/kahadb/KahaDBStoreBrokerTest.java

Author: gtully
Date: Wed Jun 10 14:59:02 2009
New Revision: 783384

URL: http://svn.apache.org/viewvc?rev=783384&view=rev
Log:
resolve https://issues.apache.org/activemq/browse/AMQ-2285 - pull file locking outside setting opened state so that an open does not ocurr unless the lock is available, sorts out Npe on shutdown

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBStoreBrokerTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java?rev=783384&r1=783383&r2=783384&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java Wed Jun 10 14:59:02 2009
@@ -218,26 +218,25 @@
 	 * @throws IOException
 	 */
 	public void open() throws IOException {
+		File lockFileName = new File(directory, "lock");
+		lockFile = new LockFile(lockFileName, true);
+		if (failIfDatabaseIsLocked) {
+		    lockFile.lock();
+		} else {
+		    while (true) {
+		        try {
+		            lockFile.lock();
+		            break;
+		        } catch (IOException e) {
+		            LOG.info("Database "+lockFileName+" is locked... waiting " + (DATABASE_LOCKED_WAIT_DELAY / 1000) + " seconds for the database to be unlocked. Reason: " + e);
+		            try {
+		                Thread.sleep(DATABASE_LOCKED_WAIT_DELAY);
+		            } catch (InterruptedException e1) {
+		            }
+		        }
+		    }
+		}
 		if( opened.compareAndSet(false, true) ) {
-            File lockFileName = new File(directory, "lock");
-            lockFile = new LockFile(lockFileName, true);
-	        if (failIfDatabaseIsLocked) {
-	            lockFile.lock();
-	        } else {
-	            while (true) {
-	                try {
-	                    lockFile.lock();
-	                    break;
-	                } catch (IOException e) {
-	                    LOG.info("Database "+lockFileName+" is locked... waiting " + (DATABASE_LOCKED_WAIT_DELAY / 1000) + " seconds for the database to be unlocked. Reason: " + e);
-	                    try {
-	                        Thread.sleep(DATABASE_LOCKED_WAIT_DELAY);
-	                    } catch (InterruptedException e1) {
-	                    }
-	                }
-	            }
-	        }
-	        
             getJournal().start();
             
 	        loadPageFile();
@@ -312,7 +311,7 @@
 	
     public void unload() throws IOException, InterruptedException {
         synchronized (indexMutex) {
-            if( pageFile.isLoaded() ) {
+            if( pageFile != null && pageFile.isLoaded() ) {
                 metadata.state = CLOSED_STATE;
                 metadata.firstInProgressTransactionLocation = getFirstInProgressTxLocation();
     

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBStoreBrokerTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBStoreBrokerTest.java?rev=783384&r1=783383&r2=783384&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBStoreBrokerTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/store/kahadb/KahaDBStoreBrokerTest.java Wed Jun 10 14:59:02 2009
@@ -17,11 +17,9 @@
 package org.apache.activemq.store.kahadb;
 
 import java.io.File;
-import java.net.URI;
 
 import junit.framework.Test;
 
-import org.apache.activemq.broker.BrokerFactory;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.BrokerTest;