activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r661435 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/ main/java/org/apache/activemq/kaha/impl/ main/java/org/apache/activemq/kaha/impl/async/ main/java/org/apache/activemq/kaha/impl/index/ main/java/org/apach...
Date Thu, 29 May 2008 19:11:21 GMT
Author: chirino
Date: Thu May 29 12:11:20 2008
New Revision: 661435

URL: http://svn.apache.org/viewvc?rev=661435&view=rev
Log:
Provide better error messages when directories cannot be created.


Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/hash/HashTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Thu May 29 12:11:20 2008
@@ -448,9 +448,9 @@
             BrokerRegistry.getInstance().bind(getBrokerName(), this);
 
             
-            LOG.info("Using Persistence Adapter: " + getPersistenceAdapter());
             getPersistenceAdapter().setUsageManager(getProducerSystemUsage());
             getPersistenceAdapter().setBrokerName(getBrokerName());
+            LOG.info("Using Persistence Adapter: " + getPersistenceAdapter());
             if (deleteAllMessagesOnStartup) {
                 deleteAllMessages();
             }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/KahaStore.java
Thu May 29 12:11:20 2008
@@ -103,7 +103,7 @@
         this.mode = mode;
         this.storeSize = storeSize;
         this.directory = directory;
-        this.directory.mkdirs();
+        IOHelper.mkdirs(this.directory);
     }
 
     public synchronized void close() throws IOException {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/AsyncDataManager.java
Thu May 29 12:11:20 2008
@@ -40,6 +40,7 @@
 import org.apache.activemq.kaha.impl.async.DataFileAppender.WriteKey;
 import org.apache.activemq.thread.Scheduler;
 import org.apache.activemq.util.ByteSequence;
+import org.apache.activemq.util.IOHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -190,15 +191,15 @@
         Scheduler.executePeriodically(cleanupTask, 1000 * 30);
     }
 
-	public void lock() throws IOException {
-		synchronized (this) {
-			if( controlFile == null ) {
-		        directory.mkdirs();
-				controlFile = new ControlFile(new File(directory, filePrefix + "control"), CONTROL_RECORD_MAX_LENGTH);
-			}
+    public void lock() throws IOException {
+        synchronized (this) {
+            if (controlFile == null) {
+                IOHelper.mkdirs(directory);
+                controlFile = new ControlFile(new File(directory, filePrefix + "control"),
CONTROL_RECORD_MAX_LENGTH);
+            }
             controlFile.lock();
         }
-	}
+    }
 
     protected Location recoveryCheck(DataFile dataFile, Location location) throws IOException
{
         if (location == null) {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/IndexManager.java
Thu May 29 12:11:20 2008
@@ -183,7 +183,7 @@
 
     protected void initialize() throws IOException {
         file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name) );
-        file.getParentFile().mkdirs();        
+        IOHelper.mkdirs(file.getParentFile());        
         indexFile = new RandomAccessFile(file, mode);
         reader = new StoreIndexReader(indexFile);
         writer = new StoreIndexWriter(indexFile, name, redoLog);

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/hash/HashIndex.java
Thu May 29 12:11:20 2008
@@ -436,7 +436,7 @@
     private void openIndexFile() throws IOException {
         if (indexFile == null) {
             file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name));
-            file.getParentFile().mkdirs();
+            IOHelper.mkdirs(file.getParentFile());
             indexFile = new RandomAccessFile(file, "rw");
         }
     }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/impl/index/tree/TreeIndex.java
Thu May 29 12:11:20 2008
@@ -404,7 +404,7 @@
     protected void openIndexFile() throws IOException {
         if (indexFile == null) {
             file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name));
-            file.getParentFile().mkdirs();
+            IOHelper.mkdirs(file.getParentFile());
             indexFile = new RandomAccessFile(file, "rw");
         }
     }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapter.java
Thu May 29 12:11:20 2008
@@ -30,6 +30,7 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
+
 import org.apache.activeio.journal.Journal;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.BrokerServiceAware;
@@ -164,12 +165,12 @@
         if (this.directoryArchive == null) {
             this.directoryArchive = new File(this.directory,"archive");
         }
-        this.directory.mkdirs();
+        IOHelper.mkdirs(this.directory);
         lockFile = new RandomAccessFile(new File(directory, "lock"), "rw");
         lock();
         LOG.info("AMQStore starting using directory: " + directory); 
         if (archiveDataLogs) {
-            this.directoryArchive.mkdirs();
+            IOHelper.mkdirs(this.directoryArchive);
         }
 
         if (this.usageManager != null) {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaPersistenceAdapter.java
Thu May 29 12:11:20 2008
@@ -23,6 +23,7 @@
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicLong;
+
 import org.apache.activemq.broker.ConnectionContext;
 import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.activemq.command.ActiveMQQueue;
@@ -49,8 +50,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import sun.misc.Perf.GetPerfAction;
-
 /**
  * @org.apache.xbean.XBean
  * @version $Revision: 1.4 $
@@ -328,7 +327,11 @@
                 file = new File(file, IOHelper.toFileSystemSafeName(brokerName) + "-kahastore");
                 setDirectory(file);
             }
-            this.directory.mkdirs();
+            try {
+                IOHelper.mkdirs(this.directory);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
             wireFormat.setCacheEnabled(false);
             wireFormat.setTightEncodingEnabled(true);
         }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/kahadaptor/KahaReferenceStoreAdapter.java
Thu May 29 12:11:20 2008
@@ -26,10 +26,8 @@
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.locks.Lock;
 
 import org.apache.activemq.broker.ConnectionContext;
-import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.command.ActiveMQTopic;
 import org.apache.activemq.command.MessageId;
@@ -41,7 +39,6 @@
 import org.apache.activemq.kaha.MessageIdMarshaller;
 import org.apache.activemq.kaha.Store;
 import org.apache.activemq.kaha.StoreFactory;
-import org.apache.activemq.kaha.impl.StoreLockedExcpetion;
 import org.apache.activemq.kaha.impl.index.hash.HashIndex;
 import org.apache.activemq.store.MessageStore;
 import org.apache.activemq.store.ReferenceStore;
@@ -49,6 +46,7 @@
 import org.apache.activemq.store.TopicMessageStore;
 import org.apache.activemq.store.TopicReferenceStore;
 import org.apache.activemq.store.amq.AMQTx;
+import org.apache.activemq.util.IOHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -295,7 +293,7 @@
     protected synchronized Store getStateStore() throws IOException {
         if (this.stateStore == null) {
             File stateDirectory = new File(getDirectory(), "kr-state");
-            stateDirectory.mkdirs();
+            IOHelper.mkdirs(stateDirectory);
             this.stateStore = createStateStore(getDirectory());
         }
         return this.stateStore;
@@ -325,8 +323,8 @@
 
     private Store createStateStore(File directory) {
         File stateDirectory = new File(directory, "state");
-        stateDirectory.mkdirs();
         try {
+            IOHelper.mkdirs(stateDirectory);
             return StoreFactory.open(stateDirectory, "rw");
         } catch (IOException e) {
             LOG.error("Failed to create the state store", e);

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.java Thu
May 29 12:11:20 2008
@@ -171,5 +171,17 @@
         MAX_FILE_NAME_LENGTH = Integer.valueOf(System.getProperty("MaximumFileNameLength","64")).intValue();
            
     }
 
-   
+    
+    public static void mkdirs(File dir) throws IOException {
+        if (dir.exists()) {
+            if (!dir.isDirectory()) {
+                throw new IOException("Failed to create directory '" + dir +"', regular file
already existed with that name");
+            }
+            
+        } else {
+            if (!dir.mkdirs()) {
+                throw new IOException("Failed to create directory '" + dir+"'");
+            }
+        }
+    }
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/hash/HashTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/hash/HashTest.java?rev=661435&r1=661434&r2=661435&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/hash/HashTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/kaha/impl/index/hash/HashTest.java
Thu May 29 12:11:20 2008
@@ -45,7 +45,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         directory = new File(IOHelper.getDefaultDataDirectory());
-        directory.mkdirs();
+        IOHelper.mkdirs(directory);
         IOHelper.deleteChildren(directory);
         indexManager = new IndexManager(directory, "im-hash-test", "rw", null,
                 new AtomicLong());



Mime
View raw message