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

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@783384 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2009-06-10 14:59:02 +00:00
parent a88a513e3c
commit 38b840a61f
2 changed files with 19 additions and 22 deletions

View File

@ -218,7 +218,6 @@ public class MessageDatabase {
* @throws IOException * @throws IOException
*/ */
public void open() throws IOException { public void open() throws IOException {
if( opened.compareAndSet(false, true) ) {
File lockFileName = new File(directory, "lock"); File lockFileName = new File(directory, "lock");
lockFile = new LockFile(lockFileName, true); lockFile = new LockFile(lockFileName, true);
if (failIfDatabaseIsLocked) { if (failIfDatabaseIsLocked) {
@ -237,7 +236,7 @@ public class MessageDatabase {
} }
} }
} }
if( opened.compareAndSet(false, true) ) {
getJournal().start(); getJournal().start();
loadPageFile(); loadPageFile();
@ -312,7 +311,7 @@ public class MessageDatabase {
public void unload() throws IOException, InterruptedException { public void unload() throws IOException, InterruptedException {
synchronized (indexMutex) { synchronized (indexMutex) {
if( pageFile.isLoaded() ) { if( pageFile != null && pageFile.isLoaded() ) {
metadata.state = CLOSED_STATE; metadata.state = CLOSED_STATE;
metadata.firstInProgressTransactionLocation = getFirstInProgressTxLocation(); metadata.firstInProgressTransactionLocation = getFirstInProgressTxLocation();

View File

@ -17,11 +17,9 @@
package org.apache.activemq.store.kahadb; package org.apache.activemq.store.kahadb;
import java.io.File; import java.io.File;
import java.net.URI;
import junit.framework.Test; import junit.framework.Test;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.BrokerTest; import org.apache.activemq.broker.BrokerTest;