You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2006/04/09 17:06:35 UTC

svn commit: r392749 - /james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java

Author: bago
Date: Sun Apr  9 08:06:34 2006
New Revision: 392749

URL: http://svn.apache.org/viewcvs?rev=392749&view=rev
Log:
Added conservative synchronization to MimeMessageWrapper (JAMES-474)
Hint by Martijn Brinkers

Modified:
    james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java

Modified: james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java?rev=392749&r1=392748&r2=392749&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/MimeMessageWrapper.java Sun Apr  9 08:06:34 2006
@@ -147,8 +147,8 @@
      * with data.
      * @see MimeMessageSource
      */
-    public String getSourceId() {
-        return source.getSourceId();
+    public synchronized String getSourceId() {
+        return source != null ? source.getSourceId() : null;
     }
 
     /**
@@ -161,16 +161,19 @@
         if (headers != null) {
             //Another thread has already loaded these headers
             return;
-        }
-        try {
-            InputStream in = source.getInputStream();
+        } else if (source != null) { 
             try {
-                headers = createInternetHeaders(in);
-            } finally {
-                IOUtil.shutdownStream(in);
+                InputStream in = source.getInputStream();
+                try {
+                    headers = createInternetHeaders(in);
+                } finally {
+                    IOUtil.shutdownStream(in);
+                }
+            } catch (IOException ioe) {
+                throw new MessagingException("Unable to parse headers from stream: " + ioe.getMessage(), ioe);
             }
-        } catch (IOException ioe) {
-            throw new MessagingException("Unable to parse headers from stream: " + ioe.getMessage(), ioe);
+        } else {
+            throw new MessagingException("loadHeaders called for a message with no source, contentStream or stream");
         }
     }
 
@@ -205,14 +208,14 @@
      *
      * @return whether the message has been modified
      */
-    public boolean isModified() {
+    public synchronized boolean isModified() {
         return headersModified || bodyModified || modified;
     }
 
     /**
      * Rewritten for optimization purposes
      */
-    public void writeTo(OutputStream os) throws IOException, MessagingException {
+    public synchronized void writeTo(OutputStream os) throws IOException, MessagingException {
         if (!isModified()) {
             // We do not want to instantiate the message... just read from source
             // and write to this outputstream
@@ -241,7 +244,7 @@
         writeTo(headerOs, bodyOs, new String[0]);
     }
 
-    public void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList) throws IOException, MessagingException {
+    public synchronized void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList) throws IOException, MessagingException {
         if (!isModified()) {
             //We do not want to instantiate the message... just read from source
             //  and write to this outputstream
@@ -391,7 +394,7 @@
     }
 
 
-    private void checkModifyHeaders() throws MessagingException {
+    private synchronized void checkModifyHeaders() throws MessagingException {
         if (headers == null) {
             loadHeaders();
         }
@@ -442,10 +445,9 @@
     }
 
     /**
-     * TODO fixme
      * @see javax.mail.internet.MimeMessage#parse(java.io.InputStream)
      */
-    protected void parse(InputStream is) throws MessagingException {
+    protected synchronized void parse(InputStream is) throws MessagingException {
         // the super implementation calls
         // headers = createInternetHeaders(is);
         super.parse(is);
@@ -458,7 +460,7 @@
      * 
      * @see javax.mail.internet.MimeMessage#createInternetHeaders(java.io.InputStream)
      */
-    protected InternetHeaders createInternetHeaders(InputStream is) throws MessagingException {
+    protected synchronized InternetHeaders createInternetHeaders(InputStream is) throws MessagingException {
 
         // Keep this: skip the headers from the stream
         // we could put that code in the else and simple write an "header" skipping



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