james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1029113 - 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 16:46:20 GMT
Author: norman
Date: Sat Oct 30 16:46:20 2010
New Revision: 1029113

URL: http://svn.apache.org/viewvc?rev=1029113&view=rev
Log:
Make sure the shared MimeMessageSource will not get confused on multiple dispose() calls on
the same instance. For this we keep track of the instances (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/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=1029113&r1=1029112&r2=1029113&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 16:46:20 2010
@@ -78,6 +78,7 @@ public class MimeMessageInputStreamSourc
      */
     public MimeMessageInputStreamSource(String key, InputStream in)
             throws MessagingException {
+        super();
         //We want to immediately read this into a temporary file
         //Create a temp file and channel the input stream into it
         OutputStream fout = null;
@@ -119,6 +120,7 @@ public class MimeMessageInputStreamSourc
     }
 
     public MimeMessageInputStreamSource(String key) throws MessagingException {
+        super();
         try {
             file = File.createTempFile(key, ".m64");
             sourceId = file.getCanonicalPath();

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=1029113&r1=1029112&r2=1029113&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 16:46:20 2010
@@ -23,6 +23,8 @@ 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;
 
@@ -34,7 +36,12 @@ import org.apache.james.lifecycle.Dispos
  * @see MimeMessageWrapper
  */
 public abstract class MimeMessageSource implements Disposable{
-    private int shares = 0;
+    private final List<MimeMessageSource> shares = new ArrayList<MimeMessageSource>();
+    
+    
+    public MimeMessageSource() {
+        shares.add(this);
+    }
     
     /**
      * Returns a unique String ID that represents the location from where 
@@ -90,20 +97,23 @@ public abstract class MimeMessageSource 
      * 
      * @return instance
      */
-    public final synchronized MimeMessageSource share() {
-        shares++;
-        return this;
+    public final SharedMimeMessageSource share() {
+        synchronized (shares) {
+            SharedMimeMessageSource share = new SharedMimeMessageSource(this);
+            return share;
+        }
+       
     }
 
     /**
      * Dispose this instance if its not shared anymore
      */
-    public final synchronized void dispose() {
-        if (shares < 1) {
-            disposeSource();
+    public final void dispose() {
+        synchronized (shares) {
+            if (shares.size() == 0) {
+                disposeSource();
+            }
         }
-        shares--;
-
     }
     
     /**
@@ -111,4 +121,39 @@ public abstract class MimeMessageSource 
      */
     protected abstract void disposeSource();
 
+    
+    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();
+        }
+        
+        public MimeMessageSource getWrapped() {
+            return source;
+        }
+        
+    }
 }

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=1029113&r1=1029112&r2=1029113&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
Sat Oct 30 16:46:20 2010
@@ -57,6 +57,8 @@ public class MimeMessageStreamRepository
      * @param key The key for the particular stream in the stream repository to be used by
this data source.
      */
     public MimeMessageStreamRepositorySource(StreamRepository sr, String repositoryName,
String key) {
+        super();
+
         this.sr = sr;
         this.repositoryName = repositoryName;
         this.key = key;

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=1029113&r1=1029112&r2=1029113&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 16:46:20 2010
@@ -85,6 +85,8 @@ public class MimeMessageJDBCSource exten
      */
     public MimeMessageJDBCSource(JDBCMailRepository repository,
             String key, StreamRepository sr) throws IOException {
+        super();
+
         if (repository == null) {
             throw new IOException("Repository is null");
         }
@@ -100,6 +102,7 @@ public class MimeMessageJDBCSource exten
         // this is optional
         retrieveMessageBodySizeSQL =
             repository.sqlQueries.getSqlString("retrieveMessageBodySizeSQL");
+    
     }
 
     /**



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