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 rd...@apache.org on 2007/10/26 23:30:59 UTC

svn commit: r588781 - in /james/server/trunk: phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/ torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/

Author: rdonkin
Date: Fri Oct 26 14:30:58 2007
New Revision: 588781

URL: http://svn.apache.org/viewvc?rev=588781&view=rev
Log:
Read-write locking to prevent deadlocks. See JAMES-808 (https://issues.apache.org/jira/browse/JAMES-808).

Modified:
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java
    james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
    james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
    james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java?rev=588781&r1=588780&r2=588781&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/mailboxmanager/torque/TorqueMailboxTestCase.java Fri Oct 26 14:30:58 2007
@@ -36,6 +36,7 @@
 import org.apache.james.mailboxmanager.tracking.UidChangeTracker;
 import org.apache.torque.TorqueException;
 import org.apache.torque.util.Criteria;
+import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
 
 public class TorqueMailboxTestCase extends AbstractTorqueTestCase {
 
@@ -48,7 +49,8 @@
         MailboxRow mr = new MailboxRow("#users.tuser.INBOX", 100);
         mr.save();
         mr=MailboxRowPeer.retrieveByName("#users.tuser.INBOX");
-        TorqueMailbox torqueMailbox = new TorqueMailbox(mr, new UidChangeTracker(null,"#users.tuser.INBOX",100),null);
+        TorqueMailbox torqueMailbox = new TorqueMailbox(mr, new UidChangeTracker(null,"#users.tuser.INBOX",100),
+                new WriterPreferenceReadWriteLock(),null);
         torqueMailbox.addListener(new MailboxListenerCollector(), MessageResult.NOTHING);
         assertEquals(0,torqueMailbox.getMessageCount());
         

Modified: james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=588781&r1=588780&r2=588781&view=diff
==============================================================================
--- james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java (original)
+++ james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java Fri Oct 26 14:30:58 2007
@@ -59,6 +59,7 @@
 import org.apache.torque.TorqueException;
 import org.apache.torque.util.Criteria;
 
+import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
 import com.sun.mail.util.CRLFOutputStream;
 import com.workingdogs.village.DataSetException;
 
@@ -74,10 +75,13 @@
 
     private UidToKeyConverter uidToKeyConverter;
     
-    TorqueMailbox(MailboxRow mailboxRow, UidChangeTracker tracker, Log log) {
+    private final ReadWriteLock lock;
+    
+    TorqueMailbox(final MailboxRow mailboxRow, final UidChangeTracker tracker, final ReadWriteLock lock, final Log log) {
         setLog(log);
         this.mailboxRow = mailboxRow;
         this.tracker = tracker;
+        this.lock = lock;
         tracker.addMailboxListener(getEventDispatcher());
         getUidToKeyConverter().setUidValidity(mailboxRow.getUidValidity());
     }
@@ -99,96 +103,113 @@
     }
 
     public int getMessageCount() throws MailboxManagerException {
-        checkAccess();
         try {
-            return getMailboxRow().countMessages();
-        } catch (Exception e) {
+            lock.readLock().acquire();
+            try {
+                checkAccess();
+                try {
+                    return getMailboxRow().countMessages();
+                } catch (Exception e) {
+                    throw new MailboxManagerException(e);
+                }
+            } finally {
+                lock.readLock().release();
+            }
+        } catch (InterruptedException e) {
             throw new MailboxManagerException(e);
         }
     }
 
     public MessageResult appendMessage(MimeMessage message, Date internalDate,
             int result) throws MailboxManagerException {
-        checkAccess();
-        final MailboxRow myMailboxRow;
         try {
-            myMailboxRow = getMailboxRow().consumeNextUid();
-        } catch (TorqueException e) {
-            throw new MailboxManagerException(e);
-        } catch (SQLException e) {
-            throw new MailboxManagerException(e);
-        }
-        if (myMailboxRow != null) {
-            try {
-                // To be thread safe, we first get our own copy and the
-                // exclusive
-                // Uid
-                // TODO create own message_id and assign uid later
-                // at the moment it could lead to the situation that uid 5 is
-                // insertet long before 4, when
-                // mail 4 is big and comes over a slow connection.
-                long uid = myMailboxRow.getLastUid();
-                this.mailboxRow = myMailboxRow;
-
-                MessageRow messageRow = new MessageRow();
-                messageRow.setMailboxId(getMailboxRow().getMailboxId());
-                messageRow.setUid(uid);
-                messageRow.setInternalDate(internalDate);
-
-                // TODO very ugly size mesurement
-                ByteArrayOutputStream sizeBos = new ByteArrayOutputStream();
-                message.writeTo(new CRLFOutputStream(sizeBos));
-                messageRow.setSize(sizeBos.size());
-                MessageFlags messageFlags = new MessageFlags();
-                messageFlags.setFlags(message.getFlags());
-                messageRow.addMessageFlags(messageFlags);
+            lock.readLock().acquire();
+            try {
+                checkAccess();
+                final MailboxRow myMailboxRow;
+                try {
+                    myMailboxRow = getMailboxRow().consumeNextUid();
+                } catch (TorqueException e) {
+                    throw new MailboxManagerException(e);
+                } catch (SQLException e) {
+                    throw new MailboxManagerException(e);
+                }
+                if (myMailboxRow != null) {
+                    try {
+                        // To be thread safe, we first get our own copy and the
+                        // exclusive
+                        // Uid
+                        // TODO create own message_id and assign uid later
+                        // at the moment it could lead to the situation that uid 5 is
+                        // insertet long before 4, when
+                        // mail 4 is big and comes over a slow connection.
+                        long uid = myMailboxRow.getLastUid();
+                        this.mailboxRow = myMailboxRow;
+
+                        MessageRow messageRow = new MessageRow();
+                        messageRow.setMailboxId(getMailboxRow().getMailboxId());
+                        messageRow.setUid(uid);
+                        messageRow.setInternalDate(internalDate);
+
+                        // TODO very ugly size mesurement
+                        ByteArrayOutputStream sizeBos = new ByteArrayOutputStream();
+                        message.writeTo(new CRLFOutputStream(sizeBos));
+                        messageRow.setSize(sizeBos.size());
+                        MessageFlags messageFlags = new MessageFlags();
+                        messageFlags.setFlags(message.getFlags());
+                        messageRow.addMessageFlags(messageFlags);
 
-                int line_number = 0;
+                        int line_number = 0;
 
-                for (Enumeration lines = message.getAllHeaderLines(); lines
+                        for (Enumeration lines = message.getAllHeaderLines(); lines
                         .hasMoreElements();) {
-                    String line = (String) lines.nextElement();
-                    int colon = line.indexOf(": ");
-                    if (colon > 0) {
-                        line_number++;
-                        MessageHeader mh = new MessageHeader();
-                        mh.setLineNumber(line_number);
-                        mh.setField(line.substring(0, colon));
-                        // TODO avoid unlikely IOOB Exception
-                        mh.setValue(line.substring(colon + 2));
-                        messageRow.addMessageHeader(mh);
-                    }
-                }
+                            String line = (String) lines.nextElement();
+                            int colon = line.indexOf(": ");
+                            if (colon > 0) {
+                                line_number++;
+                                MessageHeader mh = new MessageHeader();
+                                mh.setLineNumber(line_number);
+                                mh.setField(line.substring(0, colon));
+                                // TODO avoid unlikely IOOB Exception
+                                mh.setValue(line.substring(colon + 2));
+                                messageRow.addMessageHeader(mh);
+                            }
+                        }
+
+                        MessageBody mb = new MessageBody();
 
-                MessageBody mb = new MessageBody();
+                        InputStream is = message.getInputStream();
+
+                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                        byte[] buf = new byte[4096];
+                        int read;
+                        while ((read = is.read(buf)) > 0) {
+                            baos.write(buf, 0, read);
+                        }
 
-                InputStream is = message.getInputStream();
+                        mb.setBody(baos.toByteArray());
+                        messageRow.addMessageBody(mb);
 
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                byte[] buf = new byte[4096];
-                int read;
-                while ((read = is.read(buf)) > 0) {
-                    baos.write(buf, 0, read);
-                }
-
-                mb.setBody(baos.toByteArray());
-                messageRow.addMessageBody(mb);
-
-                messageRow.save();
-                MessageResult messageResult = fillMessageResult(messageRow,
-                        result | MessageResult.UID);
-                checkForScanGap(uid);
-                getUidChangeTracker().found(messageResult, null);
-                return messageResult;
-            } catch (Exception e) {
-                throw new MailboxManagerException(e);
+                        messageRow.save();
+                        MessageResult messageResult = fillMessageResult(messageRow,
+                                result | MessageResult.UID);
+                        checkForScanGap(uid);
+                        getUidChangeTracker().found(messageResult, null);
+                        return messageResult;
+                    } catch (Exception e) {
+                        throw new MailboxManagerException(e);
+                    }
+                } else {
+                    // mailboxRow==null
+                    getUidChangeTracker().mailboxNotFound();
+                    throw new MailboxManagerException("Mailbox has been deleted");
+                }
+            } finally {
+                lock.readLock().release();
             }
-        } else {
-            // mailboxRow==null
-            getUidChangeTracker().mailboxNotFound();
-            throw new MailboxManagerException("Mailbox has been deleted");
+        } catch (InterruptedException e) {
+            throw new MailboxManagerException(e);
         }
-
     }
 
     private void checkForScanGap(long uid) throws MailboxManagerException, TorqueException, MessagingException {
@@ -238,27 +259,35 @@
 
     public MessageResult[] getMessages(GeneralMessageSet set, int result)
             throws MailboxManagerException {
-        checkAccess();
-        set=toUidSet(set);
-        if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
-            return new MessageResult[0];
-        }
-        UidRange range = uidRangeForMessageSet(set);
         try {
-            Criteria c = criteriaForMessageSet(set);
-            c.add(MessageFlagsPeer.MAILBOX_ID,getMailboxRow().getMailboxId());
-            List l = MessageRowPeer.doSelectJoinMessageFlags(c);
-            MessageResult[] messageResults = fillMessageResult(l, result
-                    | MessageResult.UID | MessageResult.FLAGS);
-            checkForScanGap(range.getFromUid());
-            getUidChangeTracker().found(range, messageResults, null);
-            return messageResults;
-        } catch (TorqueException e) {
-            throw new MailboxManagerException(e);
-        } catch (MessagingException e) {
+            lock.readLock().acquire();
+            try {
+                checkAccess();
+                set=toUidSet(set);
+                if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
+                    return new MessageResult[0];
+                }
+                UidRange range = uidRangeForMessageSet(set);
+                try {
+                    Criteria c = criteriaForMessageSet(set);
+                    c.add(MessageFlagsPeer.MAILBOX_ID,getMailboxRow().getMailboxId());
+                    List l = MessageRowPeer.doSelectJoinMessageFlags(c);
+                    MessageResult[] messageResults = fillMessageResult(l, result
+                            | MessageResult.UID | MessageResult.FLAGS);
+                    checkForScanGap(range.getFromUid());
+                    getUidChangeTracker().found(range, messageResults, null);
+                    return messageResults;
+                } catch (TorqueException e) {
+                    throw new MailboxManagerException(e);
+                } catch (MessagingException e) {
+                    throw new MailboxManagerException(e);
+                }
+            } finally {
+                lock.readLock().release();
+            }
+        } catch (InterruptedException e) {
             throw new MailboxManagerException(e);
         }
-
     }
 
     private static UidRange uidRangeForMessageSet(GeneralMessageSet set)
@@ -337,72 +366,111 @@
     }
 
     public int getRecentCount(boolean reset) throws MailboxManagerException {
-        checkAccess();
-        Flags flags = new Flags();
-        flags.add(Flags.Flag.RECENT);
         try {
-            int count = getMailboxRow().countMessages(flags, true);
-            if (reset) {
-                getMailboxRow().resetRecent();
+            lock.readLock().acquire();
+            try {
+                checkAccess();
+                Flags flags = new Flags();
+                flags.add(Flags.Flag.RECENT);
+                try {
+                    int count = getMailboxRow().countMessages(flags, true);
+                    if (reset) {
+                        getMailboxRow().resetRecent();
+                    }
+                    return count;
+                } catch (TorqueException e) {
+                    throw new MailboxManagerException(e);
+                } catch (DataSetException e) {
+                    throw new MailboxManagerException(e);
+                }
+            } finally {
+                lock.readLock().release();
             }
-            return count;
-        } catch (TorqueException e) {
-            throw new MailboxManagerException(e);
-        } catch (DataSetException e) {
+        } catch (InterruptedException e) {
             throw new MailboxManagerException(e);
         }
-
     }
 
     public MessageResult getFirstUnseen(int result)
             throws MailboxManagerException {
-        checkAccess();
-        Criteria c = new Criteria();
-        c.addAscendingOrderByColumn(MessageRowPeer.UID);
-        c.setLimit(1);
-        c.setSingleRecord(true);
-        
-        c.addJoin(MessageFlagsPeer.MAILBOX_ID, MessageRowPeer.MAILBOX_ID);
-        c.addJoin(MessageRowPeer.UID, MessageFlagsPeer.UID);
-        
-        MessageFlagsPeer.addFlagsToCriteria(new Flags(Flags.Flag.SEEN), false,
-                c);
-        
         try {
-            List messageRows = getMailboxRow().getMessageRows(c);
-            if (messageRows.size() > 0) {
-                MessageResult messageResult=fillMessageResult((MessageRow) messageRows.get(0), result | MessageResult.UID);
-                if (messageResult!=null) {
-                    checkForScanGap(messageResult.getUid());
-                    getUidChangeTracker().found(messageResult,null);
+            lock.readLock().acquire();
+            try {
+                checkAccess();
+                Criteria c = new Criteria();
+                c.addAscendingOrderByColumn(MessageRowPeer.UID);
+                c.setLimit(1);
+                c.setSingleRecord(true);
+
+                c.addJoin(MessageFlagsPeer.MAILBOX_ID, MessageRowPeer.MAILBOX_ID);
+                c.addJoin(MessageRowPeer.UID, MessageFlagsPeer.UID);
+
+                MessageFlagsPeer.addFlagsToCriteria(new Flags(Flags.Flag.SEEN), false,
+                        c);
+
+                try {
+                    List messageRows = getMailboxRow().getMessageRows(c);
+                    if (messageRows.size() > 0) {
+                        MessageResult messageResult=fillMessageResult((MessageRow) messageRows.get(0), result | MessageResult.UID);
+                        if (messageResult!=null) {
+                            checkForScanGap(messageResult.getUid());
+                            getUidChangeTracker().found(messageResult,null);
+                        }
+
+                        return messageResult;
+                    } else {
+                        return null;
+                    }
+                } catch (TorqueException e) {
+                    throw new MailboxManagerException(e);
+                } catch (MessagingException e) {
+                    throw new MailboxManagerException(e);
                 }
-                
-                return messageResult;
-            } else {
-                return null;
+            } finally {
+                lock.readLock().release();
             }
-        } catch (TorqueException e) {
-            throw new MailboxManagerException(e);
-        } catch (MessagingException e) {
+        } catch (InterruptedException e) {
             throw new MailboxManagerException(e);
         }
-
     }
 
     public int getUnseenCount() throws MailboxManagerException {
-        checkAccess();
         try {
-            final int count = getMailboxRow().countMessages(new Flags(Flags.Flag.SEEN), false);
-            return count;
-        } catch (TorqueException e) {
-            throw new MailboxManagerException(e);
-        } catch (DataSetException e) {
+            lock.readLock().acquire();
+            try {
+                checkAccess();
+                try {
+                    final int count = getMailboxRow().countMessages(new Flags(Flags.Flag.SEEN), false);
+                    return count;
+                } catch (TorqueException e) {
+                    throw new MailboxManagerException(e);
+                } catch (DataSetException e) {
+                    throw new MailboxManagerException(e);
+                }
+            } finally {
+                lock.readLock().release();
+            }
+        } catch (InterruptedException e) {
             throw new MailboxManagerException(e);
         }
     }
 
     public MessageResult[] expunge(GeneralMessageSet set, int result)
             throws MailboxManagerException {
+        try {
+            lock.writeLock().acquire();
+            try {
+                return doExpunge(set, result);
+            } finally {
+                lock.writeLock().release();
+            }
+
+        } catch (InterruptedException e) {
+            throw new MailboxManagerException(e);
+        }
+    }
+
+    private MessageResult[] doExpunge(GeneralMessageSet set, int result) throws MailboxManagerException {
         checkAccess();
         set=toUidSet(set);  
         if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
@@ -437,6 +505,20 @@
     public void setFlags(Flags flags, boolean value, boolean replace,
             GeneralMessageSet set, MailboxListener silentListener)
             throws MailboxManagerException {
+        try {
+            lock.writeLock().acquire();
+            try {
+                doSetFlags(flags, value, replace, set, silentListener);
+            } finally {
+                lock.writeLock().release();
+            }
+
+        } catch (InterruptedException e) {
+            throw new MailboxManagerException(e);
+        }
+    }
+
+    private void doSetFlags(Flags flags, boolean value, boolean replace, GeneralMessageSet set, MailboxListener silentListener) throws MailboxManagerException {
         checkAccess();
         set=toUidSet(set);  
         if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
@@ -494,27 +576,49 @@
     }
 
     public synchronized long getUidValidity() throws MailboxManagerException {
-        checkAccess();
-        return getMailboxRow().getUidValidity();
+        try {
+            lock.writeLock().acquire();
+            try {
+                checkAccess();
+                final long result = getMailboxRow().getUidValidity();
+                return result;
+            } finally {
+                lock.writeLock().release();
+            }
+
+        } catch (InterruptedException e) {
+            throw new MailboxManagerException(e);
+        }
+
     }
 
     public synchronized long getUidNext() throws MailboxManagerException {
-        checkAccess();
         try {
-            MailboxRow myMailboxRow = MailboxRowPeer.retrieveByPK(mailboxRow.getPrimaryKey());
-            if (myMailboxRow != null) {
-                mailboxRow=myMailboxRow;
-                getUidChangeTracker().foundLastUid(mailboxRow.getLastUid());
-                return getUidChangeTracker().getLastUid() + 1;
-            } else {
-                getUidChangeTracker().mailboxNotFound();
-                throw new MailboxManagerException("Mailbox has been deleted");
+            lock.writeLock().acquire();
+            try {
+                checkAccess();
+                try {
+                    MailboxRow myMailboxRow = MailboxRowPeer.retrieveByPK(mailboxRow.getPrimaryKey());
+                    if (myMailboxRow != null) {
+                        mailboxRow=myMailboxRow;
+                        getUidChangeTracker().foundLastUid(mailboxRow.getLastUid());
+                        return getUidChangeTracker().getLastUid() + 1;
+                    } else {
+                        getUidChangeTracker().mailboxNotFound();
+                        throw new MailboxManagerException("Mailbox has been deleted");
+                    }
+                } catch (NoRowsException e) {
+                    throw new MailboxManagerException(e);
+                } catch (TooManyRowsException e) {
+                    throw new MailboxManagerException(e);
+                } catch (TorqueException e) {
+                    throw new MailboxManagerException(e);
+                }
+            } finally {
+                lock.writeLock().release();
             }
-        } catch (NoRowsException e) {
-            throw new MailboxManagerException(e);
-        } catch (TooManyRowsException e) {
-            throw new MailboxManagerException(e);
-        } catch (TorqueException e) {
+
+        } catch (InterruptedException e) {
             throw new MailboxManagerException(e);
         }
     }
@@ -551,18 +655,27 @@
 
     public MessageResult[] search(GeneralMessageSet set, SearchTerm searchTerm,
             int result) throws MailboxManagerException {
-        checkAccess();
-        set=toUidSet(set);
-        if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
-            return new MessageResult[0];
-        }
-        final Log log = getLog();
-        // TODO implementation
-        if (log.isWarnEnabled()) {
-            log.warn("Search is not yet implemented. Sorry.");
+        try {
+            lock.readLock().acquire();
+            try {
+                checkAccess();
+                set=toUidSet(set);
+                if (!set.isValid() || set.getType()==GeneralMessageSet.TYPE_NOTHING) {
+                    return new MessageResult[0];
+                }
+                final Log log = getLog();
+                // TODO implementation
+                if (log.isWarnEnabled()) {
+                    log.warn("Search is not yet implemented. Sorry.");
+                }
+                MessageResult[] results = {};
+                return results;
+            } finally {
+                lock.readLock().release();
+            }
+        } catch (InterruptedException e) {
+            throw new MailboxManagerException(e);
         }
-        MessageResult[] results = {};
-        return results;
     }
     
     protected UidToKeyConverter getUidToKeyConverter() {
@@ -573,8 +686,19 @@
     }
 
     public void remove(GeneralMessageSet set) throws MailboxManagerException {
-        setFlags(new Flags(Flags.Flag.DELETED), true, false, set, null);
-        expunge(set, MessageResult.NOTHING);
+        try {
+            lock.writeLock().acquire();
+            try {
+                final Flags flags = new Flags(Flags.Flag.DELETED);
+                doSetFlags(flags, true, false, set, null);
+                doExpunge(set, MessageResult.NOTHING);
+            } finally {
+                lock.writeLock().release();
+            }
+
+        } catch (InterruptedException e) {
+            throw new MailboxManagerException(e);
+        }
     }
 
     private GeneralMessageSet toUidSet(GeneralMessageSet set) {

Modified: james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java?rev=588781&r1=588780&r2=588781&view=diff
==============================================================================
--- james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java (original)
+++ james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java Fri Oct 26 14:30:58 2007
@@ -45,6 +45,7 @@
 import org.apache.torque.TorqueException;
 import org.apache.torque.util.CountHelper;
 import org.apache.torque.util.Criteria;
+import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
 
 public class TorqueMailboxManager implements MailboxManager {
 
@@ -55,10 +56,13 @@
     
     protected Log log;
 
-    public TorqueMailboxManager(User authUser, MailboxCache mailboxCache, Log log) {
+    private final ReadWriteLock lock;
+    
+    public TorqueMailboxManager(final User authUser, final MailboxCache mailboxCache, final ReadWriteLock lock, final Log log) {
         this.mailboxCache=mailboxCache;
         this.authUser=authUser;
         this.log=log;
+        this.lock = lock;
     }
     
     public MailboxSession getMailboxSession(String mailboxName,
@@ -110,8 +114,10 @@
                         getMailboxCache().add(mailboxName, tracker);
                     }
                     getLog().info("created ImapMailboxSession "+mailboxName);
-                    return new ImapMailboxSessionWrapper(new TorqueMailbox(
-                            mailboxRow, tracker,getLog()));
+                    final TorqueMailbox torqueMailbox = new TorqueMailbox(
+                                                mailboxRow, tracker, lock, getLog());
+                    final ImapMailboxSessionWrapper wrapper = new ImapMailboxSessionWrapper(torqueMailbox);
+                    return wrapper;
                 } else {
                     getLog().info("Mailbox '" + mailboxName + "' not found.");
                     getMailboxCache().notFound(mailboxName);

Modified: james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java
URL: http://svn.apache.org/viewvc/james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java?rev=588781&r1=588780&r2=588781&view=diff
==============================================================================
--- james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java (original)
+++ james/server/trunk/torque-mailboxmanager-function/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManagerFactory.java Fri Oct 26 14:30:58 2007
@@ -58,6 +58,9 @@
 import org.apache.torque.util.BasePeer;
 import org.apache.torque.util.Transaction;
 
+import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
+import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
+
 public class TorqueMailboxManagerFactory implements MailboxManagerFactory,
         Configurable, Initializable, Serviceable, LogEnabled {
 
@@ -70,18 +73,24 @@
     private Log log;
 
     private FileSystem fileSystem;
+    
+    private final ReadWriteLock lock;
 
     private static final String[] tableNames = new String[] {
             MailboxRowPeer.TABLE_NAME, MessageRowPeer.TABLE_NAME,
             MessageHeaderPeer.TABLE_NAME, MessageBodyPeer.TABLE_NAME,
             MessageFlagsPeer.TABLE_NAME };
 
+    public TorqueMailboxManagerFactory() {
+        lock = new WriterPreferenceReadWriteLock();
+    }
+    
     public MailboxManager getMailboxManagerInstance(User user)
             throws MailboxManagerException {
         if (!initialized) {
             throw new MailboxManagerException("must be initialized first!");
         }
-        return new TorqueMailboxManager(user, getMailboxCache(), getLog());
+        return new TorqueMailboxManager(user, getMailboxCache(), lock, getLog());
     }
 
     public void initialize() throws Exception {



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