activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r571306 - in /activemq/trunk/activemq-core/src/main/java/org/apache/activemq: broker/ kaha/ kaha/impl/ kaha/impl/index/ kaha/impl/index/hash/ kaha/impl/index/tree/ store/amq/ store/kahadaptor/ util/
Date Thu, 30 Aug 2007 20:49:42 GMT
Author: chirino
Date: Thu Aug 30 13:49:41 2007
New Revision: 571306

URL: http://svn.apache.org/viewvc?rev=571306&view=rev
Log:
Satitized the filenames that the KahaStore uses. 

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/StoreFactory.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/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/amq/AMQPersistenceAdapterFactory.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/HexSupport.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IOHelper.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=571306&r1=571305&r2=571306&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 Aug 30 13:49:41 2007
@@ -1087,7 +1087,7 @@
                     String str = result ? "Successfully deleted" : "Failed to delete";
                     LOG.info(str + " temporary storage");
                 }
-                tempDataStore = StoreFactory.open(getTmpDataDirectory().getPath(), "rw");
+                tempDataStore = StoreFactory.open(getTmpDataDirectory(), "rw");
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java?rev=571306&r1=571305&r2=571306&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/kaha/StoreFactory.java
Thu Aug 30 13:49:41 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.kaha;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -44,6 +45,18 @@
     }
     
     /**
+     * Open or create a Store
+     * 
+     * @param directory
+     * @param mode
+     * @return
+     * @throws IOException
+     */
+    public static Store open(File directory, String mode) throws IOException {
+        return new KahaStore(directory, mode, new AtomicLong());
+    }
+    
+    /**
      * open or create a Store
      * @param name
      * @param mode
@@ -54,6 +67,21 @@
     public static Store open(String name, String mode, AtomicLong size) throws IOException
{
         return new KahaStore(name, mode,size);
     }
+    
+
+    /**
+     * Open or create a Store
+     * 
+     * @param directory
+     * @param mode
+     * @param size
+     * @return
+     * @throws IOException
+     */
+    public static Store open(File directory, String mode, AtomicLong size) throws IOException
{
+        return new KahaStore(directory, mode, size);
+    }
+    
 
     /**
      * Delete a database
@@ -64,6 +92,18 @@
      */
     public static boolean delete(String name) throws IOException {
         KahaStore store = new KahaStore(name, "rw");
+        return store.delete();
+    }
+    
+    /**
+     * Delete a database
+     * 
+     * @param directory
+     * @return true if successful
+     * @throws IOException
+     */
+    public static boolean delete(File directory) throws IOException {
+        KahaStore store = new KahaStore(directory, "rw");
         return store.delete();
     }
 }

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=571306&r1=571305&r2=571306&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 Aug 30 13:49:41 2007
@@ -43,6 +43,7 @@
 import org.apache.activemq.kaha.impl.index.IndexItem;
 import org.apache.activemq.kaha.impl.index.IndexManager;
 import org.apache.activemq.kaha.impl.index.RedoStoreIndexItem;
+import org.apache.activemq.util.IOHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -84,14 +85,22 @@
 
     
     public KahaStore(String name, String mode) throws IOException {
-        this(name,mode,new AtomicLong());
+    	this(new File(IOHelper.toFileSystemSafeName(name)), mode, new AtomicLong());
     }
-    
+
+    public KahaStore(File directory, String mode) throws IOException {
+    	this(directory, mode, new AtomicLong());
+    }
+
     public KahaStore(String name, String mode,AtomicLong storeSize) throws IOException {
+    	this(new File(IOHelper.toFileSystemSafeName(name)), mode, storeSize);
+    }
+    
+    public KahaStore(File directory, String mode, AtomicLong storeSize) throws IOException
{
         this.mode = mode;
         this.storeSize = storeSize;
-        directory = new File(name);
-        directory.mkdirs();
+        this.directory = directory;
+        this.directory.mkdirs();
     }
 
     public synchronized void close() throws IOException {

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=571306&r1=571305&r2=571306&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 Aug 30 13:49:41 2007
@@ -22,6 +22,7 @@
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.activemq.kaha.impl.DataManager;
+import org.apache.activemq.util.IOHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -175,7 +176,7 @@
     }
 
     protected void initialize() throws IOException {
-        file = new File(directory, NAME_PREFIX + name);
+        file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name) );
         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=571306&r1=571305&r2=571306&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 Aug 30 13:49:41 2007
@@ -26,6 +26,7 @@
 import org.apache.activemq.kaha.impl.index.IndexManager;
 import org.apache.activemq.util.DataByteArrayInputStream;
 import org.apache.activemq.util.DataByteArrayOutputStream;
+import org.apache.activemq.util.IOHelper;
 import org.apache.activemq.util.LRUCache;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -390,7 +391,7 @@
 
     private void openIndexFile() throws IOException {
         if (indexFile == null) {
-            file = new File(directory, NAME_PREFIX + name);
+            file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name));
             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=571306&r1=571305&r2=571306&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 Aug 30 13:49:41 2007
@@ -26,6 +26,7 @@
 import org.apache.activemq.kaha.impl.index.IndexManager;
 import org.apache.activemq.util.DataByteArrayInputStream;
 import org.apache.activemq.util.DataByteArrayOutputStream;
+import org.apache.activemq.util.IOHelper;
 import org.apache.activemq.util.LRUCache;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -405,7 +406,7 @@
 
     protected void openIndexFile() throws IOException {
         if (indexFile == null) {
-            file = new File(directory, NAME_PREFIX + name);
+            file = new File(directory, NAME_PREFIX + IOHelper.toFileSystemSafeName(name));
             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=571306&r1=571305&r2=571306&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 Aug 30 13:49:41 2007
@@ -127,7 +127,7 @@
             if (brokerService != null) {
                 this.directory = brokerService.getBrokerDataDirectory();
             } else {
-                this.directory = new File(IOHelper.getDefaultDataDirectory(), brokerName);
+                this.directory = new File(IOHelper.getDefaultDataDirectory(), IOHelper.toFileSystemSafeName(brokerName));
                 this.directory = new File(directory, "amqstore");
             }
         }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapterFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapterFactory.java?rev=571306&r1=571305&r2=571306&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapterFactory.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/amq/AMQPersistenceAdapterFactory.java
Thu Aug 30 13:49:41 2007
@@ -56,7 +56,7 @@
      */
     public File getDataDirectory() {
         if (this.dataDirectory == null) {
-            this.dataDirectory = new File(IOHelper.getDefaultDataDirectory(), brokerName);
+            this.dataDirectory = new File(IOHelper.getDefaultDataDirectory(), IOHelper.toFileSystemSafeName(brokerName));
         }
         return this.dataDirectory;
     }

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=571306&r1=571305&r2=571306&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 Aug 30 13:49:41 2007
@@ -195,7 +195,7 @@
                 theStore.delete();
             }
         } else {
-            StoreFactory.delete(getStoreName());
+            StoreFactory.delete(getStoreDirectory());
         }
     }
 
@@ -255,7 +255,7 @@
 
     protected synchronized Store getStore() throws IOException {
         if (theStore == null) {
-            theStore = StoreFactory.open(getStoreName(), "rw",storeSize);
+            theStore = StoreFactory.open(getStoreDirectory(), "rw",storeSize);
             theStore.setMaxDataFileLength(maxDataFileLength);
         }
         return theStore;
@@ -266,6 +266,11 @@
         return directory.getAbsolutePath();
     }
 
+    private File getStoreDirectory() {
+        initialize();
+        return directory;
+    }
+
     public String toString() {
         return "KahaPersistenceAdapter(" + getStoreName() + ")";
     }
@@ -301,7 +306,7 @@
             initialized = true;
             if (this.directory == null) {
                 File file = new File(IOHelper.getDefaultDataDirectory());
-                file = new File(file, brokerName + "-kahastore");
+                file = new File(file, IOHelper.toFileSystemSafeName(brokerName) + "-kahastore");
                 setDirectory(file);
             }
             this.directory.mkdirs();

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=571306&r1=571305&r2=571306&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 Aug 30 13:49:41 2007
@@ -270,7 +270,7 @@
             }
         } else {
             File stateDirectory = new File(getDirectory(), "kr-state");
-            StoreFactory.delete(stateDirectory.getAbsolutePath());
+            StoreFactory.delete(stateDirectory);
         }
     }
 
@@ -278,7 +278,7 @@
         File stateDirectory = new File(directory, "state");
         stateDirectory.mkdirs();
         try {
-            return StoreFactory.open(stateDirectory.getAbsolutePath(), "rw");
+            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/HexSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/HexSupport.java?rev=571306&r1=571305&r2=571306&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/HexSupport.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/HexSupport.java Thu
Aug 30 13:49:41 2007
@@ -41,6 +41,9 @@
         "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed",
"ee", "ef",
         "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd",
"fe", "ff",
     };
+    private static final int[] INT_OFFSETS = new int[]{
+    	24,16,8,0
+    };
     
     private HexSupport() {
     }
@@ -67,6 +70,24 @@
         StringBuffer rc = new StringBuffer(bytes.length * 2);
         for (int i = 0; i < bytes.length; i++) {
             rc.append(HEX_TABLE[0xFF & bytes[i]]);
+        }
+        return rc.toString();
+    }
+
+    /**
+     * 
+     * @param value 
+     * @param trim if the leading 0's should be trimmed off.
+     * @return
+     */
+    public static String toHexFromInt(int value, boolean trim) {
+        StringBuffer rc = new StringBuffer(INT_OFFSETS.length*2);
+        for (int i = 0; i < INT_OFFSETS.length; i++) {
+        	int b = 0xFF & (value>>INT_OFFSETS[i]);
+        	if( !(trim && b == 0) ) { 
+        		rc.append(HEX_TABLE[b]);
+        		trim=false;
+        	}
         }
         return rc.toString();
     }

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=571306&r1=571305&r2=571306&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
Aug 30 13:49:41 2007
@@ -44,4 +44,32 @@
             return "";
         }
     }
+
+    /**
+     * Converts any string into a string that is safe to use as a file name.
+     * The result will only include ascii characters and numbers, and the "-","_", and "."
characters.
+     *
+     * @param name
+     * @return
+     */
+    public static String toFileSystemSafeName( String name ) {
+    	int size = name.length();
+    	StringBuffer rc = new StringBuffer(size*2);
+    	for (int i = 0; i < size; i++) {
+			char c = name.charAt(i);
+			boolean valid = c >= 'a' && c <= 'z';
+			valid = valid || (c >= 'A' && c <= 'Z');
+			valid = valid || (c >= '0' && c <= '9');
+			valid = valid || (c == '_') || (c == '-') || (c == '.') || (c == '/') || (c == '\\');
+			
+			if(  valid ) {
+				rc.append(c);
+			} else {
+				// Encode the character using hex notation
+				rc.append('#');
+				rc.append(HexSupport.toHexFromInt(c, true));
+			}
+		}
+    	return rc.toString();
+    }
 }



Mime
View raw message