james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1372278 - /james/server/trunk/queue-file/src/main/java/org/apache/james/queue/file/FileMailQueue.java
Date Mon, 13 Aug 2012 07:10:53 GMT
Author: eric
Date: Mon Aug 13 07:10:53 2012
New Revision: 1372278

URL: http://svn.apache.org/viewvc?rev=1372278&view=rev
Log:
Ensure FileMailQueue survive James restart (JAMES-1429) + Code format

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=1372278&r1=1372277&r2=1372278&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
Mon Aug 13 07:10:53 2012
@@ -52,13 +52,10 @@ import org.slf4j.Logger;
 /**
  * {@link ManageableMailQueue} implementation which use the fs to store {@link Mail}'s
  * 
- * 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.
- * 
- * 
- * 
+ * On create of the {@link FileMailQueue} the {@link #init()} will get called. This takes
care of 
+ * loading the needed meta-data into memory for fast access.
  */
 public class FileMailQueue implements ManageableMailQueue {
-
     private final ConcurrentHashMap<String, FileItem> keyMappings = new ConcurrentHashMap<String,
FileMailQueue.FileItem>();
     private final BlockingQueue<String> inmemoryQueue = new LinkedBlockingQueue<String>();
     private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
@@ -78,36 +75,35 @@ public class FileMailQueue implements Ma
         this.sync = sync;
         this.queueDir = new File(parentDir, queuename);
         this.queueDirName = queueDir.getAbsolutePath();
-
         init();
     }
     
     private void init() throws IOException {
         
         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);
             }
-            String[] files = queueDir.list(new FilenameFilter() {
-                
+            
+            String[] files = qDir.list(new FilenameFilter() {
                 @Override
                 public boolean accept(File dir, String name) {
-                    if (name.endsWith(OBJECT_EXTENSION)) {
-                        return true;
-                    }
-                    return false;
+                    return name.endsWith(OBJECT_EXTENSION);
                 }
             });
-            for (int a = 0; a < files.length; a++) {
+
+            for (int a=0; a < files.length; a++) {
+                
                 final String name = files[a];
                 ObjectInputStream oin = null;
                 
-
                 try {
+
                     final String msgFileName = name.substring(0, name.length() - OBJECT_EXTENSION.length())
+ MSG_EXTENSION;
 
-                    FileItem item = new FileItem(queueDirName + "/" + name, queueDirName
+ "/" + msgFileName);
+                    FileItem item = new FileItem(qDir.getAbsolutePath() + File.separator
+ name, qDir.getAbsolutePath() + File.separator + msgFileName);
 
                     oin = new ObjectInputStream(new FileInputStream(item.getObjectFile()));
                     Mail mail = (Mail) oin.readObject();
@@ -116,7 +112,6 @@ public class FileMailQueue implements Ma
                         next = 0L;
                     }
 
-
                     final String key = mail.getName();
                     keyMappings.put(key, item);
                     if (next <= System.currentTimeMillis()) {
@@ -163,9 +158,6 @@ public class FileMailQueue implements Ma
         }
     }
     
-    
-    
-    
     @Override
     public void enQueue(final Mail mail, long delay, TimeUnit unit) throws MailQueueException
{
         final String key = mail.getName() + "-" + COUNTER.incrementAndGet();
@@ -192,7 +184,6 @@ public class FileMailQueue implements Ma
             if (sync) out.getFD().sync();
             
             keyMappings.put(key, item);
-        
 
             if (delay > 0) {
                 mail.setAttribute(NEXT_DELIVERY, System.currentTimeMillis() + unit.toMillis(delay));
@@ -252,8 +243,6 @@ public class FileMailQueue implements Ma
 
     }
 
-    
-    
     @Override
     public void enQueue(Mail mail) throws MailQueueException {
         enQueue(mail, 0, TimeUnit.MILLISECONDS);
@@ -353,12 +342,10 @@ public class FileMailQueue implements Ma
             return in.newStream(0, -1);
         }
 
-
         @Override
         public long getMessageSize() throws IOException {
             return file.length();
         }
-        
 
         /**
          * @see org.apache.james.core.MimeMessageSource#disposeSource()
@@ -376,8 +363,6 @@ public class FileMailQueue implements Ma
     
     /**
      * Helper class which is used to reference the path to the object and msg file
-     * 
-     *
      */
     private final class FileItem {
         private String objectfile;
@@ -415,6 +400,7 @@ public class FileMailQueue implements Ma
         }
         
     }
+
     @Override
     public long getSize() throws MailQueueException {
         return keyMappings.size();



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


Mime
View raw message