Author: norman
Date: Fri Oct 14 18:27:08 2011
New Revision: 1183454

URL: http://svn.apache.org/viewvc?rev=1183454&view=rev
Log:
Start to implement remove method of FileMailQueue

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=1183454&r1=1183453&r2=1183454&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
 Fri Oct 14 18:27:08 2011
@@ -59,31 +59,30 @@ import org.slf4j.Logger;
  */
 public class FileMailQueue implements ManageableMailQueue {
 
-    private ConcurrentHashMap<String, FileItem> keyMappings = new 
ConcurrentHashMap<String, FileMailQueue.FileItem>();
-    private BlockingQueue<String> inmemoryQueue = new 
LinkedBlockingQueue<String>();
-    private ScheduledExecutorService scheduler = 
Executors.newSingleThreadScheduledExecutor();
+    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();
     private final static AtomicLong COUNTER = new AtomicLong();
-    private final String queuename;
-    private final File parentDir;
-    private String queueDirName;
+    private final String queueDirName;
+    private final File queueDir;
     private final Logger log;
-    private boolean sync;
+    
+    private final boolean sync;
     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;
         this.log = log;
         this.sync = sync;
+        this.queueDir = new File(parentDir, queuename);
+        this.queueDirName = queueDir.getAbsolutePath();
+
         init();
     }
     
     private void init() throws IOException {
-        File queueDir = new File(parentDir, queuename);
-        queueDirName = queueDir.getAbsolutePath();
         
         for (int i = 1; i <= SPLITCOUNT; i++) {
             File qDir = new File(queueDir, Integer.toString(i));
@@ -272,10 +271,11 @@ public class FileMailQueue implements Ma
 
             }
             final String key = k;
+            final FileItem fitem = item;
             ObjectInputStream oin = null;
             try {
-                final File objectFile = new File(item.getObjectFile());
-                final File msgFile = new File(item.getMessageFile());
+                final File objectFile = new File(fitem.getObjectFile());
+                final File msgFile = new File(fitem.getMessageFile());
                 oin = new ObjectInputStream(new FileInputStream(objectFile));
                 final Mail mail = (Mail) oin.readObject();
                 mail.setMessage(new MimeMessageCopyOnWriteProxy(new 
FileMimeMessageSource(msgFile)));
@@ -296,16 +296,7 @@ public class FileMailQueue implements Ma
                                 throw new MailQueueException("Unable to 
rollback", e);
                             }
                         } else {
-                            keyMappings.remove(key);
-                            if (!objectFile.delete()) {
-                                if (log.isInfoEnabled()) {
-                                    log.info("Unable to delete file " + 
objectFile);
-                                }
-                            }
-                            if (!msgFile.delete()) {
-                                if (log.isInfoEnabled()) {
-                                    log.info("Unable to delete file " + 
msgFile);
-                                }                            }
+                            fitem.delete();
                         }
 
                         LifecycleUtil.dispose(mail);
@@ -388,7 +379,7 @@ public class FileMailQueue implements Ma
      * 
      *
      */
-    private final static class FileItem {
+    private final class FileItem {
         private String objectfile;
         private String messagefile;
 
@@ -406,6 +397,23 @@ public class FileMailQueue implements Ma
             return messagefile;
         }
         
+        public void delete() throws MailQueueException {
+            File msgFile = new File(getMessageFile());
+            File objectFile = new File(getObjectFile());
+            
+            if (objectFile.exists()) {
+                if (!objectFile.delete()) {
+                    throw new MailQueueException("Unable to delete mail");
+                } 
+            }
+            if (msgFile.exists()) {
+                if (!msgFile.delete()) {
+                    log.debug("Remove of msg file for mail failed");
+                }
+                
+            }
+        }
+        
     }
     @Override
     public long getSize() throws MailQueueException {
@@ -434,21 +442,11 @@ public class FileMailQueue implements Ma
             Entry<String, FileItem> entry = items.next();
             FileItem item = entry.getValue();
             String key = entry.getKey();
-            File msgFile = new File(item.getMessageFile());
-            File objectFile = new File(item.getObjectFile());
-            if (objectFile.exists()) {
-                if (!objectFile.delete()) {
-                    throw new MailQueueException("Unable to delete mail " + 
key);
-                } 
-            }
+           
+            item.delete();
             keyMappings.remove(key);
             count++;
-            if (msgFile.exists()) {
-                if (!msgFile.delete()) {
-                    log.debug("Remove of msg file for mail " + key +" failed");
-                }
-                
-            }
+
         }
         return count;
     }
@@ -460,6 +458,19 @@ public class FileMailQueue implements Ma
      */
     @Override
     public long remove(Type type, String value) throws MailQueueException {
+        switch (type) {
+        case Name:
+            FileItem item = keyMappings.remove(value);
+            if (item != null) {
+                item.delete();
+                return 1;
+            } else {
+                return 0;
+            }
+            
+        default:
+            break;
+        }
         throw new MailQueueException("Not supported yet");
 
     }



---------------------------------------------------------------------
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