james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1029021 - in /james/server/trunk: core-library/src/main/java/org/apache/james/core/ mail-file/src/main/java/org/apache/james/mailrepository/file/ mail-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/
Date Sat, 30 Oct 2010 11:10:46 GMT
Author: norman
Date: Sat Oct 30 11:10:46 2010
New Revision: 1029021

URL: http://svn.apache.org/viewvc?rev=1029021&view=rev
Log:
Re-enable efficient handling of wrapped MimeMessageWrapper by sharing the MimeMessageSource
(JAMES-1095)

Modified:
    james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
    james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageSource.java
    james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java
    james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageAvalonSource.java
    james/server/trunk/mail-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/MimeMessageJDBCSource.java

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java?rev=1029021&r1=1029020&r2=1029021&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
Sat Oct 30 11:10:46 2010
@@ -26,7 +26,6 @@ import javax.mail.util.SharedFileInputSt
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
-import org.apache.james.lifecycle.Disposable;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
@@ -49,8 +48,7 @@ import java.util.List;
  *
  */
 public class MimeMessageInputStreamSource
-    extends MimeMessageSource
-    implements Disposable {
+    extends MimeMessageSource {
 
     private final List<InputStream> streams = new ArrayList<InputStream>();
 
@@ -179,10 +177,10 @@ public class MimeMessageInputStreamSourc
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.lifecycle.Disposable#dispose()
+     * @see org.apache.james.core.MimeMessageSource#disposeSource()
      */
-    public void dispose() {
-        // explicit close all streams
+    public void disposeSource() {
+     // explicit close all streams
         for (int i = 0; i < streams.size(); i++) {
             IOUtils.closeQuietly(streams.get(i));
         }
@@ -193,4 +191,5 @@ public class MimeMessageInputStreamSourc
         file = null;
     }
 
+
 }

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageSource.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageSource.java?rev=1029021&r1=1029020&r2=1029021&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageSource.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageSource.java
Sat Oct 30 11:10:46 2010
@@ -24,6 +24,8 @@ package org.apache.james.core;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.james.lifecycle.Disposable;
+
 /**
  * This defines a reusable datasource that can supply an input stream with
  * MimeMessage data.  This allows a MimeMessageWrapper or other classes to
@@ -31,7 +33,9 @@ import java.io.InputStream;
  *
  * @see MimeMessageWrapper
  */
-public abstract class MimeMessageSource {
+public abstract class MimeMessageSource implements Disposable{
+    private int shares = 0;
+    
     /**
      * Returns a unique String ID that represents the location from where 
      * this file is loaded.  This will be used to identify where the data 
@@ -80,5 +84,31 @@ public abstract class MimeMessageSource 
         }
         return size;
     }
+    
+    /**
+     * Share this instance and increase the share count
+     * 
+     * @return instance
+     */
+    public final synchronized MimeMessageSource share() {
+        shares++;
+        return this;
+    }
+
+    /**
+     * Dispose this instance if its not shared anymore
+     */
+    public final synchronized void dispose() {
+        if (shares < 1) {
+            disposeSource();
+        }
+        shares--;
+
+    }
+    
+    /**
+     * Get called by {@link #dispose()} if this instance is not shared anymore
+     */
+    protected abstract void disposeSource();
 
 }

Modified: james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java?rev=1029021&r1=1029020&r2=1029021&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java
(original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/core/MimeMessageWrapper.java
Sat Oct 30 11:10:46 2010
@@ -34,6 +34,7 @@ import javax.mail.internet.MimeMessage;
 import javax.mail.util.SharedByteArrayInputStream;
 
 import java.io.BufferedWriter;
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -117,19 +118,21 @@ public class MimeMessageWrapper
         
         // if the original is an unmodified MimeMessageWrapped we clone the headers and
         // take its source.
-        /* Temporary commented out because of JAMES-474
         if (original instanceof MimeMessageWrapper && !((MimeMessageWrapper) original).bodyModified)
{
-            source = ((MimeMessageWrapper) original).source;
+            // call share so we are sure it will not dispose the message to early
+            source = ((MimeMessageWrapper) original).source.share();
             // this probably speed up things
             if (((MimeMessageWrapper) original).headers != null) {
                 ByteArrayOutputStream temp = new ByteArrayOutputStream();
+                
+                //TODO: Remove the byte[] array usage
                 InternetHeaders ih = ((MimeMessageWrapper) original).headers;
                 MimeMessageUtil.writeHeadersTo(ih.getAllHeaderLines(),temp);
                 headers = createInternetHeaders(new ByteArrayInputStream(temp.toByteArray()));
                 headersModified = ((MimeMessageWrapper) original).headersModified;
             }
         }
-        */
+     
         
         if (source == null) {
             ByteArrayOutputStream bos;

Modified: james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageAvalonSource.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageAvalonSource.java?rev=1029021&r1=1029020&r2=1029021&view=diff
==============================================================================
--- james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageAvalonSource.java
(original)
+++ james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageAvalonSource.java
Sat Oct 30 11:10:46 2010
@@ -98,4 +98,12 @@ public class MimeMessageAvalonSource ext
         }
         return size;
     }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.core.MimeMessageSource#disposeSource()
+     */
+    protected void disposeSource() {
+        // nothing todo here
+    }
 }

Modified: james/server/trunk/mail-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/MimeMessageJDBCSource.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mail-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/MimeMessageJDBCSource.java?rev=1029021&r1=1029020&r2=1029021&view=diff
==============================================================================
--- james/server/trunk/mail-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/MimeMessageJDBCSource.java
(original)
+++ james/server/trunk/mail-jdbc/src/main/java/org/apache/james/mailrepository/jdbc/MimeMessageJDBCSource.java
Sat Oct 30 11:10:46 2010
@@ -274,4 +274,12 @@ public class MimeMessageJDBCSource exten
         }
         return result;
      }
+
+     /*
+      * (non-Javadoc)
+      * @see org.apache.james.core.MimeMessageSource#disposeSource()
+      */
+    protected void disposeSource() {
+        // nothing todo here
+    }
 }



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