Author: norman
Date: Thu Sep 29 17:18:59 2011
New Revision: 1177373

URL: http://svn.apache.org/viewvc?rev=1177373&view=rev
Log:
Use sub-directories for storing the messages to queue. This helps to keep the 
performance at a good level even if the queue contains thousands of messages. 
See JAMES-1323

Modified:
    
james/server/trunk/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java

Modified: 
james/server/trunk/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java?rev=1177373&r1=1177372&r2=1177373&view=diff
==============================================================================
--- 
james/server/trunk/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
 (original)
+++ 
james/server/trunk/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
 Thu Sep 29 17:18:59 2011
@@ -55,9 +55,7 @@ import org.slf4j.Logger;
  * On create of the {@link FileMailQueue} the {@link #init()} will get called. 
This takes care of load the needed meta-data into memory for fast access.
  * 
  * 
- * TODO: Split emails in sub-directories to make it more efficient with huge 
queues
  * 
- *
  */
 public class FileMailQueue implements ManageableMailQueue {
 
@@ -73,7 +71,8 @@ public class FileMailQueue implements Ma
     private final static String MSG_EXTENSION = ".msg";
     private final static String OBJECT_EXTENSION = ".obj";
     private final static String NEXT_DELIVERY = "FileQueueNextDelivery";
-    
+    private final static int SPLITCOUNT = 10;
+
     public FileMailQueue(File parentDir, String queuename, boolean sync, 
Logger log) throws IOException {
         this.queuename = queuename;
         this.parentDir = parentDir;
@@ -86,11 +85,11 @@ public class FileMailQueue implements Ma
         File queueDir = new File(parentDir, queuename);
         queueDirName = queueDir.getAbsolutePath();
         
-        if (!queueDir.exists()) {
-            if (!queueDir.mkdirs()) {
-                throw new IOException("Unable to create queue directory " + 
queueDir);
+        for (int i = 1; i <= SPLITCOUNT; i++) {
+            File qDir = new File(queueDir, Integer.toString(i));
+            if (!qDir.exists() && !qDir.mkdirs()) {
+                throw new IOException("Unable to create queue directory " +  
qDir);
             }
-        } else {
             String[] files = queueDir.list(new FilenameFilter() {
                 
                 @Override
@@ -175,7 +174,10 @@ public class FileMailQueue implements Ma
         FileOutputStream foout = null;
         ObjectOutputStream oout = null;
         try {
-            String name = queueDirName + "/" + key;
+            int i = (int) (Math.random() * SPLITCOUNT + 1);
+
+            
+            String name = queueDirName + "/" + i + "/" + key;
             
             final FileItem item = new FileItem(name + OBJECT_EXTENSION, name + 
MSG_EXTENSION);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to