james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1029742 - 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 Mon, 01 Nov 2010 16:53:55 GMT
Author: norman
Date: Mon Nov  1 16:53:55 2010
New Revision: 1029742

URL: http://svn.apache.org/viewvc?rev=1029742&view=rev
Log:
Remove loading optimization which I introduced for JAMES-1095. After more debugging and reading
the code this will just make things harder to understand with no real gain. IT also leaked
temporary files

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/MimeMessageStreamRepositorySource.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=1029742&r1=1029741&r2=1029742&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
Mon Nov  1 16:53:55 2010
@@ -26,6 +26,7 @@ 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;
@@ -48,7 +49,7 @@ import java.util.List;
  *
  */
 public class MimeMessageInputStreamSource
-    extends MimeMessageSource {
+    extends MimeMessageSource implements Disposable{
 
     private final List<InputStream> streams = new ArrayList<InputStream>();
 
@@ -85,12 +86,7 @@ public class MimeMessageInputStreamSourc
         try {
             file = File.createTempFile(key, ".m64");
             fout = new BufferedOutputStream(new FileOutputStream(file));
-            int b = -1;
-            while ((b = in.read()) != -1) {
-                fout.write(b);
-            }
-            fout.flush();
-
+            IOUtils.copy(in, fout);
             sourceId = file.getCanonicalPath();
         } catch (IOException ioe) {
             throw new MessagingException("Unable to retrieve the data: " + ioe.getMessage(),
ioe);
@@ -181,7 +177,7 @@ public class MimeMessageInputStreamSourc
      * (non-Javadoc)
      * @see org.apache.james.core.MimeMessageSource#disposeSource()
      */
-    public void disposeSource() {
+    public void dispose() {
      // explicit close all streams
         for (int i = 0; i < streams.size(); i++) {
             IOUtils.closeQuietly(streams.get(i));

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=1029742&r1=1029741&r2=1029742&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
Mon Nov  1 16:53:55 2010
@@ -23,10 +23,7 @@ package org.apache.james.core;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
 
-import org.apache.james.lifecycle.Disposable;
 
 /**
  * This defines a reusable datasource that can supply an input stream with
@@ -35,13 +32,8 @@ import org.apache.james.lifecycle.Dispos
  *
  * @see MimeMessageWrapper
  */
-public abstract class MimeMessageSource implements Disposable{
-    private final List<MimeMessageSource> shares = new ArrayList<MimeMessageSource>();
-    
-    
-    public MimeMessageSource() {
-        shares.add(this);
-    }
+public abstract class MimeMessageSource {
+
     
     /**
      * Returns a unique String ID that represents the location from where 
@@ -91,80 +83,6 @@ public abstract class MimeMessageSource 
         }
         return size;
     }
-    
-    /**
-     * Share this instance and increase the share count
-     * 
-     * @return instance
-     */
-    public final SharedMimeMessageSource share() {
-        synchronized (shares) {
-            SharedMimeMessageSource share = new SharedMimeMessageSource(this);
-            return share;
-        }
-       
-    }
 
-    /**
-     * Dispose this instance if its not shared anymore
-     */
-    public final void dispose() {
-        synchronized (shares) {
-            if (shares.size() == 0) {
-                disposeSource();
-            }
-        }
-    }
-    
-    /**
-     * Get called by {@link #dispose()} if this instance is not shared anymore
-     */
-    protected abstract void disposeSource();
 
-    
-    /**
-     * Allow to share a {@link MimeMessageSource} and take care of tracking 
-     * the instances. This is needed to make sure the {@link #dispose()} is not called 
-     * to early
-     *
-     */
-    public final class SharedMimeMessageSource extends MimeMessageSource {
-
-        private MimeMessageSource source;
-
-        public SharedMimeMessageSource(MimeMessageSource source) {
-            super();
-            this.source = source;
-        }
-        
-        @Override
-        protected void disposeSource() {
-            synchronized (shares) {
-                if (shares.remove(SharedMimeMessageSource.this)) {
-                    source.dispose();
-                }
-            }
-           
-        }
-
-        @Override
-        public InputStream getInputStream() throws IOException {
-            return source.getInputStream();
-        }
-
-        @Override
-        public String getSourceId() {
-            return source.getSourceId();
-        }
-        
-        /**
-         * Return the wrapped original {@link MimeMessageSource}
-         * 
-         * @return original
-         */
-        public MimeMessageSource getOriginal() {
-            return source;
-        }
-        
-    }
 }

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=1029742&r1=1029741&r2=1029742&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
Mon Nov  1 16:53:55 2010
@@ -115,22 +115,7 @@ public class MimeMessageWrapper
     public MimeMessageWrapper(MimeMessage original) throws MessagingException {
         this(Session.getDefaultInstance(System.getProperties()));
         flags = original.getFlags();
-        
-        // if the original is an unmodified MimeMessageWrapped we clone the headers and
-        // take its source.
-        if (original instanceof MimeMessageWrapper && !((MimeMessageWrapper) original).bodyModified)
{
-            // 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) {
-                
-                InternetHeaders ih = ((MimeMessageWrapper) original).headers;
-                headers = createInternetHeaders(new InternetHeadersInputStream(ih));
-                headersModified = ((MimeMessageWrapper) original).headersModified;
-            }
-        }
-     
-        
+
         if (source == null) {
             ByteArrayOutputStream bos;
             int size = original.getSize();

Modified: james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageStreamRepositorySource.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageStreamRepositorySource.java?rev=1029742&r1=1029741&r2=1029742&view=diff
==============================================================================
--- james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageStreamRepositorySource.java
(original)
+++ james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MimeMessageStreamRepositorySource.java
Mon Nov  1 16:53:55 2010
@@ -100,12 +100,4 @@ public class MimeMessageStreamRepository
         }
         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=1029742&r1=1029741&r2=1029742&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
Mon Nov  1 16:53:55 2010
@@ -278,11 +278,4 @@ 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