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 no...@apache.org on 2010/04/27 16:51:35 UTC

svn commit: r938484 - in /james/imap/trunk: deployment/src/test/java/org/apache/james/imap/functional/jcr/ deployment/src/test/java/org/apache/james/imap/functional/jpa/ jcr/src/main/java/org/apache/james/imap/jcr/ jpa/src/main/java/org/apache/james/im...

Author: norman
Date: Tue Apr 27 14:51:34 2010
New Revision: 938484

URL: http://svn.apache.org/viewvc?rev=938484&view=rev
Log:
Remove the UidChangeTracker from the StoreMailbox implementations. We now pass the mailboxname of the event to check later if we want to handle the vent in the listener. 

Modified:
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalMailbox.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java
    james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
    james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
    james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
    james/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcherFlagsTest.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
    james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/MailboxEventAnalyser.java
    james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
    james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
    james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java Tue Apr 27 14:51:34 2010
@@ -21,6 +21,7 @@ package org.apache.james.imap.functional
 import java.io.File;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
 import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
@@ -30,6 +31,7 @@ import org.apache.james.imap.jcr.JCRGlob
 import org.apache.james.imap.jcr.JCRGlobalUserSubscriptionManager;
 import org.apache.james.imap.jcr.JCRImapConstants;
 import org.apache.james.imap.jcr.JCRUtils;
+import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.main.DefaultImapDecoderFactory;
 import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
 import org.apache.james.test.functional.HostSystem;
@@ -71,8 +73,12 @@ public class JCRHostSystem extends ImapH
 
             final DefaultImapProcessorFactory defaultImapProcessorFactory = new DefaultImapProcessorFactory();
             resetUserMetaData();
-            mailboxManager.deleteEverything();
-
+            MailboxSession session = mailboxManager.createSystemSession("test", new SimpleLog("TestLog"));
+            mailboxManager.startProcessingRequest(session);
+            mailboxManager.deleteEverything(session);
+            mailboxManager.endProcessingRequest(session);
+            mailboxManager.logout(session, false);
+            
             defaultImapProcessorFactory.configure(mailboxManager);
             configure(new DefaultImapDecoderFactory().buildImapDecoder(), new DefaultImapEncoderFactory().buildImapEncoder(), defaultImapProcessorFactory.buildImapProcessor());
         } catch (Exception e) {

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java Tue Apr 27 14:51:34 2010
@@ -25,11 +25,13 @@ import java.util.HashMap;
 import javax.persistence.EntityManagerFactory;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
 import org.apache.james.imap.functional.ImapHostSystem;
 import org.apache.james.imap.functional.InMemoryUserManager;
 import org.apache.james.imap.jpa.JPASubscriptionManager;
 import org.apache.james.imap.jpa.openjpa.OpenJPAMailboxManager;
+import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.main.DefaultImapDecoderFactory;
 import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
 import org.apache.james.test.functional.HostSystem;
@@ -46,6 +48,7 @@ public class JPAHostSystem extends ImapH
     
     private final OpenJPAMailboxManager mailboxManager;
     private final InMemoryUserManager userManager; 
+    private final EntityManagerFactory entityManagerFactory;
 
     public JPAHostSystem() throws Exception {
         HashMap<String, String> properties = new HashMap<String, String>();
@@ -64,7 +67,7 @@ public class JPAHostSystem extends ImapH
                 "org.apache.james.imap.jpa.user.model.JPASubscription)");
         
         userManager = new InMemoryUserManager();
-        final EntityManagerFactory entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties);
+        entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties);
         mailboxManager = new OpenJPAMailboxManager(userManager, new JPASubscriptionManager(entityManagerFactory), entityManagerFactory);
         
         final DefaultImapProcessorFactory defaultImapProcessorFactory = new DefaultImapProcessorFactory();
@@ -82,7 +85,12 @@ public class JPAHostSystem extends ImapH
 
     public void resetData() throws Exception {
         resetUserMetaData();
-        mailboxManager.deleteEverything();
+        MailboxSession session = mailboxManager.createSystemSession("test", new SimpleLog("TestLog"));
+        mailboxManager.startProcessingRequest(session);
+        mailboxManager.deleteEverything(session);
+        mailboxManager.endProcessingRequest(session);
+        mailboxManager.logout(session, false);
+        
     }
     
     public void resetUserMetaData() throws Exception {

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalMailbox.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalMailbox.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalMailbox.java Tue Apr 27 14:51:34 2010
@@ -30,6 +30,7 @@ import org.apache.commons.logging.Log;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.SubscriptionException;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 
 /**
  * JCR based Mailbox which use the same username and password to obtain a
@@ -41,9 +42,9 @@ public class JCRGlobalMailbox extends JC
 	private final String username;
 	private final char[] password;
 	
-	public JCRGlobalMailbox(final org.apache.james.imap.jcr.mail.model.JCRMailbox mailbox, MailboxSession session,
+	public JCRGlobalMailbox(MailboxEventDispatcher dispatcher, final org.apache.james.imap.jcr.mail.model.JCRMailbox mailbox,
 			Repository repository, String workspace, String username, char[] password, final int scaling, Log log) {
-		super(mailbox, session, repository, workspace, scaling, log);
+		super(dispatcher, mailbox, repository, workspace, scaling, log);
 		this.username = username;
 		this.password = password;
 	}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRGlobalUserMailboxManager.java Tue Apr 27 14:51:34 2010
@@ -29,6 +29,7 @@ import org.apache.james.imap.api.display
 import org.apache.james.imap.jcr.mail.JCRMailboxMapper;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.Authenticator;
 import org.apache.james.imap.store.StoreMailbox;
 import org.apache.james.imap.store.Subscriber;
@@ -63,8 +64,8 @@ public class JCRGlobalUserMailboxManager
         this(authenticator, subscriber, repository, workspace, username, password, MAX_SCALING);
     }
     
-    public void deleteEverything() throws MailboxException {
-        Session session = getSession(null);
+    public void deleteEverything(MailboxSession mailboxSession) throws MailboxException {
+        Session session = getSession(mailboxSession);
         final MailboxMapper<String> mapper = new JCRMailboxMapper(session, getScaling(), getLog());
         mapper.execute(new TransactionalMapper.Transaction() {
 
@@ -78,8 +79,8 @@ public class JCRGlobalUserMailboxManager
     }
     
     @Override
-    protected StoreMailbox<String> createMailbox(Mailbox<String> mailboxRow, MailboxSession session) {
-        JCRMailbox mailbox = new JCRGlobalMailbox((org.apache.james.imap.jcr.mail.model.JCRMailbox) mailboxRow, session, getRepository(), getWorkspace(), username, password, getScaling(), getLog());
+    protected StoreMailbox<String> createMailbox(MailboxEventDispatcher dispatcher, Mailbox<String> mailboxRow) {
+        JCRMailbox mailbox = new JCRGlobalMailbox(dispatcher, (org.apache.james.imap.jcr.mail.model.JCRMailbox) mailboxRow, getRepository(), getWorkspace(), username, password, getScaling(), getLog());
         return mailbox;
     }
     

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java Tue Apr 27 14:51:34 2010
@@ -40,6 +40,7 @@ import org.apache.james.imap.jcr.mail.mo
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.SubscriptionException;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.PasswordAwareUser;
 import org.apache.james.imap.store.StoreMailbox;
 import org.apache.james.imap.store.mail.MessageMapper;
@@ -59,8 +60,8 @@ public class JCRMailbox extends StoreMai
     private final Log log;
     private final int scaling;
     
-    public JCRMailbox(final org.apache.james.imap.jcr.mail.model.JCRMailbox mailbox, final MailboxSession session, final Repository repository, final String workspace, final int scaling, final Log log) {
-        super(mailbox, session );
+    public JCRMailbox(final MailboxEventDispatcher dispatcher, final org.apache.james.imap.jcr.mail.model.JCRMailbox mailbox, final Repository repository, final String workspace, final int scaling, final Log log) {
+        super(dispatcher, mailbox);
         this.repository = repository;
         this.workspace = workspace;
         this.log = log;
@@ -80,7 +81,7 @@ public class JCRMailbox extends StoreMai
 
     
     @Override
-    protected MailboxMembership<String> copyMessage(MailboxMembership<String> originalMessage, long uid) throws MailboxException {
+    protected MailboxMembership<String> copyMessage(MailboxMembership<String> originalMessage, long uid, MailboxSession session) throws MailboxException {
         MailboxMembership<String> newRow = new JCRMailboxMembership(getMailboxId(), uid, (JCRMailboxMembership) originalMessage, log);
         return newRow;
     }
@@ -130,14 +131,14 @@ public class JCRMailbox extends StoreMai
     }
     
     @Override
-    protected Mailbox<String> getMailboxRow() throws MailboxException {
-        final JCRMailboxMapper mapper = createMailboxMapper(getMailboxSession());
+    protected Mailbox<String> getMailboxRow(MailboxSession session) throws MailboxException {
+        final JCRMailboxMapper mapper = createMailboxMapper(session);
         return mapper.findMailboxById(getMailboxId());
     }
 
     @Override
-    protected Mailbox<String> reserveNextUid() throws MailboxException {
-        final JCRMailboxMapper mapper = createMailboxMapper(getMailboxSession());
+    protected Mailbox<String> reserveNextUid(MailboxSession session) throws MailboxException {
+        final JCRMailboxMapper mapper = createMailboxMapper(session);
         return mapper.consumeNextUid(getMailboxId());
     }
 
@@ -149,7 +150,7 @@ public class JCRMailbox extends StoreMai
      * @throws MailboxException
      */
     protected Session getSession(MailboxSession session) throws SubscriptionException {
-        PasswordAwareUser user = (PasswordAwareUser) getMailboxSession().getUser();
+        PasswordAwareUser user = (PasswordAwareUser) session.getUser();
 
         try {
             return repository.login(new SimpleCredentials(user.getUserName(), user.getPassword().toCharArray()), getWorkspace());

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java Tue Apr 27 14:51:34 2010
@@ -36,6 +36,7 @@ import org.apache.james.imap.jcr.mail.JC
 import org.apache.james.imap.mailbox.BadCredentialsException;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.Authenticator;
 import org.apache.james.imap.store.PasswordAwareMailboxSession;
 import org.apache.james.imap.store.PasswordAwareUser;
@@ -80,8 +81,8 @@ public class JCRMailboxManager extends S
     }
     
     @Override
-    protected StoreMailbox<String> createMailbox(Mailbox<String> mailboxRow, MailboxSession session) {
-        JCRMailbox mailbox = new JCRMailbox((org.apache.james.imap.jcr.mail.model.JCRMailbox) mailboxRow, session, getRepository(), getWorkspace(), getScaling(), getLog());
+    protected StoreMailbox<String> createMailbox(MailboxEventDispatcher dispatcher, Mailbox<String> mailboxRow) {
+        JCRMailbox mailbox = new JCRMailbox(dispatcher, (org.apache.james.imap.jcr.mail.model.JCRMailbox) mailboxRow, getRepository(), getWorkspace(), getScaling(), getLog());
         return mailbox;
     }
 

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java Tue Apr 27 14:51:34 2010
@@ -34,6 +34,7 @@ import org.apache.james.imap.jpa.mail.mo
 import org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.StoreMailbox;
 import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.MessageMapper;
@@ -51,8 +52,8 @@ public abstract class JPAMailbox extends
 
     protected final EntityManagerFactory entityManagerFactory;
     
-    public JPAMailbox(final Mailbox<Long> mailbox, MailboxSession session, final EntityManagerFactory entityManagerfactory) {
-        super(mailbox, session);
+    public JPAMailbox(final MailboxEventDispatcher dispatcher, final Mailbox<Long> mailbox, final EntityManagerFactory entityManagerfactory) {
+        super(dispatcher, mailbox);
         this.entityManagerFactory = entityManagerfactory;        
     }  
     
@@ -64,9 +65,9 @@ public abstract class JPAMailbox extends
     protected abstract JPAMailboxMapper createMailboxMapper(MailboxSession session);
 
     @Override
-    protected Mailbox<Long> getMailboxRow() throws MailboxException {
-        final MailboxMapper<Long> mapper = createMailboxMapper(getMailboxSession());
-        return mapper.findMailboxById(mailboxId);
+    protected Mailbox<Long> getMailboxRow(MailboxSession session) throws MailboxException {
+        final MailboxMapper<Long> mapper = createMailboxMapper(session);
+        return mapper.findMailboxById(getMailboxId());
     }
 
     
@@ -76,7 +77,7 @@ public abstract class JPAMailbox extends
         
         JPAUtils.addEntityManager(session, manager);
         
-        JPAMessageMapper mapper = new JPAMessageMapper(manager, mailboxId);
+        JPAMessageMapper mapper = new JPAMessageMapper(manager, getMailboxId());
        
         return mapper;
     }
@@ -88,14 +89,14 @@ public abstract class JPAMailbox extends
         for (Header header: headers) {
             jpaHeaders.add((JPAHeader) header);
         }
-        final MailboxMembership<Long> message = new JPAMailboxMembership(mailboxId, uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
+        final MailboxMembership<Long> message = new JPAMailboxMembership(getMailboxId(), uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
         return message;
 
        
     }
     
     @Override
-    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid) throws MailboxException{
+    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid, MailboxSession session) throws MailboxException{
         final MailboxMembership<Long> newRow = new JPAMailboxMembership(getMailboxId(), uid, (AbstractJPAMailboxMembership) originalMessage);
         return newRow;
     }
@@ -110,9 +111,9 @@ public abstract class JPAMailbox extends
      * Reserve next Uid in mailbox and return the mailbox. This method needs to be synchronized 
      * to be sure we don't get any race-condition
      */
-    protected synchronized Mailbox<Long> reserveNextUid() throws MailboxException {
-        final JPAMailboxMapper mapper = createMailboxMapper(getMailboxSession());
-        final Mailbox<Long> mailbox = mapper.consumeNextUid(mailboxId);
+    protected synchronized Mailbox<Long> reserveNextUid(MailboxSession session) throws MailboxException {
+        final JPAMailboxMapper mapper = createMailboxMapper(session);
+        final Mailbox<Long> mailbox = mapper.consumeNextUid(getMailboxId());
         return mailbox;
     } 
 }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java Tue Apr 27 14:51:34 2010
@@ -62,15 +62,8 @@ public abstract class JPAMailboxManager 
         });
     }
 
-    
-    /**
-     * Delete every Mailbox which exists
-     * 
-     * @throws MailboxException
-     */
-
-    public void deleteEverything() throws MailboxException {
-        final MailboxMapper<Long> mapper = createMailboxMapper(null);
+    public void deleteEverything(MailboxSession maibloxSession) throws MailboxException {
+        final MailboxMapper<Long> mapper = createMailboxMapper(maibloxSession);
         mapper.execute(new TransactionalMapper.Transaction() {
 
             public void run() throws MailboxException {
@@ -81,7 +74,6 @@ public abstract class JPAMailboxManager 
         });
     }
 
-
     @Override
     public void endProcessingRequest(MailboxSession session) {
         List<EntityManager> managers = JPAUtils.getEntityManagers(session);

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java Tue Apr 27 14:51:34 2010
@@ -37,6 +37,7 @@ import org.apache.james.imap.jpa.mail.mo
 import org.apache.james.imap.jpa.mail.openjpa.OpenJPAMailboxMapper;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.mail.model.Header;
 import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
@@ -50,14 +51,12 @@ public class OpenJPAMailbox extends JPAM
 
     public final static String MAILBOX_MAPPER = "MAILBOX_MAPPER";
     private final boolean useStreaming;
-    public OpenJPAMailbox(Mailbox<Long> mailbox,
-    		MailboxSession session, EntityManagerFactory entityManagerfactory) {
-		this(mailbox,session, entityManagerfactory, false);
+    public OpenJPAMailbox(MailboxEventDispatcher dispatcher, Mailbox<Long> mailbox,  EntityManagerFactory entityManagerfactory) {
+		this(dispatcher, mailbox, entityManagerfactory, false);
 	}
 
-    public OpenJPAMailbox(Mailbox<Long> mailbox,
-            MailboxSession session, EntityManagerFactory entityManagerfactory, final boolean useStreaming) {
-        super(mailbox, session, entityManagerfactory);
+    public OpenJPAMailbox(MailboxEventDispatcher dispatcher, Mailbox<Long> mailbox, EntityManagerFactory entityManagerfactory, final boolean useStreaming) {
+        super(dispatcher, mailbox, entityManagerfactory);
         this.useStreaming = useStreaming;
     }
 
@@ -76,11 +75,11 @@ public class OpenJPAMailbox extends JPAM
     }
 
     @Override
-    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid) throws MailboxException {
+    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid, MailboxSession session) throws MailboxException {
         if (useStreaming) {
             return  new JPAStreamingMailboxMembership(getMailboxId(), uid, (AbstractJPAMailboxMembership) originalMessage);
         } else {
-            return super.copyMessage(originalMessage, uid);
+            return super.copyMessage(originalMessage, uid, session);
         }
     }
 
@@ -91,7 +90,7 @@ public class OpenJPAMailbox extends JPAM
             for (Header header: headers) {
                 jpaHeaders.add((JPAHeader) header);
             }
-            return new JPAStreamingMailboxMembership(mailboxId, uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
+            return new JPAStreamingMailboxMembership(getMailboxId(), uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
         } else {
             return super.createMessage(internalDate, uid, size, bodyStartOctet, document, flags, headers, propertyBuilder);
         }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java Tue Apr 27 14:51:34 2010
@@ -26,6 +26,7 @@ import org.apache.james.imap.jpa.JPAMail
 import org.apache.james.imap.jpa.JPAUtils;
 import org.apache.james.imap.jpa.mail.openjpa.OpenJPAMailboxMapper;
 import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.Authenticator;
 import org.apache.james.imap.store.StoreMailbox;
 import org.apache.james.imap.store.Subscriber;
@@ -56,9 +57,8 @@ public class OpenJPAMailboxManager exten
         return new OpenJPAMailboxMapper(manager);
     }
 
-    protected StoreMailbox<Long> createMailbox(Mailbox<Long> mailboxRow, MailboxSession session) {
-        StoreMailbox<Long> result;
-        result = new OpenJPAMailbox(mailboxRow, session, entityManagerFactory, useStreaming);
+    protected StoreMailbox<Long> createMailbox(MailboxEventDispatcher dispatcher, Mailbox<Long> mailboxRow) {
+        StoreMailbox<Long> result =  new OpenJPAMailbox(dispatcher,mailboxRow, entityManagerFactory, useStreaming);
         return result;
     }
 }

Modified: james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java (original)
+++ james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxListener.java Tue Apr 27 14:51:34 2010
@@ -51,9 +51,10 @@ public interface MailboxListener {
      */
     public abstract class Event {
         private final long sessionId;
-
-        public Event(final long sessionId) {
+        private final String name;
+        public Event(final long sessionId, final String name) {
             this.sessionId = sessionId;
+            this.name = name;
         }
         
         /**
@@ -64,6 +65,15 @@ public interface MailboxListener {
         public long getSessionId() {
             return sessionId;
         }
+        
+        /**
+         * Return the name of the Mailbox this event belongs to. 
+         * 
+         * @return name
+         */
+        public String getMailboxName() {
+            return name;
+        }
     }
 
     /**
@@ -71,8 +81,8 @@ public interface MailboxListener {
      */
     public abstract class MailboxDeletionEvent extends Event {
 
-        public MailboxDeletionEvent(long sessionId) {
-            super(sessionId);
+        public MailboxDeletionEvent(long sessionId, String name) {
+            super(sessionId, name);
         }
     }
     
@@ -81,12 +91,12 @@ public interface MailboxListener {
      * Indicates that a mailbox has been renamed.
      */
     public abstract class MailboxRenamed extends Event {
-        public MailboxRenamed(long sessionId) {
-            super(sessionId);
+        public MailboxRenamed(long sessionId, String name) {
+            super(sessionId, name);
         }
-
         /**
          * Gets the new name for this mailbox.
+         * 
          * @return name, not null
          */
         public abstract String getNewName();
@@ -97,8 +107,8 @@ public interface MailboxListener {
      */
     public abstract class MessageEvent extends Event {
 
-        public MessageEvent(long sessionId) {
-            super(sessionId);
+        public MessageEvent(long sessionId, String name) {
+            super(sessionId, name);
         }
 
         /**
@@ -111,15 +121,20 @@ public interface MailboxListener {
 
     public abstract class Expunged extends MessageEvent {
 
-        public Expunged(long sessionId) {
-            super(sessionId);
+        public Expunged(long sessionId, String name) {
+            super(sessionId, name);
         }
     }
 
+    /**
+     * A mailbox event related to updated flags
+     * 
+     *
+     */
     public abstract class FlagsUpdated extends MessageEvent {
 
-        public FlagsUpdated(long sessionId) {
-            super(sessionId);
+        public FlagsUpdated(long sessionId, String name) {
+            super(sessionId, name);
         }
 
         /**
@@ -135,10 +150,15 @@ public interface MailboxListener {
         public abstract Iterator<Flags.Flag> flagsIterator();
     }
 
+    /**
+     * A mailbox event related to added message
+     * 
+     *
+     */
     public abstract class Added extends MessageEvent {
 
-        public Added(long sessionId) {
-            super(sessionId);
+        public Added(long sessionId, String name) {
+            super(sessionId, name);
         }
     }
 

Modified: james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java (original)
+++ james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcher.java Tue Apr 27 14:51:34 2010
@@ -52,20 +52,20 @@ public class MailboxEventDispatcher impl
         listeners.add(mailboxListener);
     }
 
-    public void added(long uid, long sessionId) {
+    public void added(long uid, long sessionId, String name) {
         pruneClosed();
-        final AddedImpl added = new AddedImpl(sessionId, uid);
+        final AddedImpl added = new AddedImpl(sessionId, name, uid);
         event(added);
     }
 
-    public void expunged(final long uid, long sessionId) {
-        final ExpungedImpl expunged = new ExpungedImpl(sessionId, uid);
+    public void expunged(final long uid, long sessionId, String name) {
+        final ExpungedImpl expunged = new ExpungedImpl(sessionId, name, uid);
         event(expunged);
     }
 
-    public void flagsUpdated(final long uid, long sessionId,
+    public void flagsUpdated(final long uid, long sessionId, final String name,
             final Flags original, final Flags updated) {
-        final FlagsUpdatedImpl flags = new FlagsUpdatedImpl(sessionId, uid,
+        final FlagsUpdatedImpl flags = new FlagsUpdatedImpl(sessionId, name, uid,
                 original, updated);
         event(flags);
     }
@@ -85,19 +85,23 @@ public class MailboxEventDispatcher impl
         return listeners.size();
     }
     
-    public void mailboxRenamed(String to, long sessionId) {
-        event(new MailboxRenamedEventImpl(to, sessionId));
+    public void mailboxRenamed(String from, String to, long sessionId) {
+        event(new MailboxRenamedEventImpl(from, to, sessionId));
     }
 
     private final static class AddedImpl extends MailboxListener.Added {
 
         private final long subjectUid;
 
-        public AddedImpl(final long sessionId, final long subjectUid) {
-            super(sessionId);
+        public AddedImpl(final long sessionId, final String name, final long subjectUid) {
+            super(sessionId, name);
             this.subjectUid = subjectUid;
         }
 
+        /*
+         * (non-Javadoc)
+         * @see org.apache.james.imap.mailbox.MailboxListener.MessageEvent#getSubjectUid()
+         */
         public long getSubjectUid() {
             return subjectUid;
         }
@@ -107,8 +111,8 @@ public class MailboxEventDispatcher impl
 
         private final long subjectUid;
 
-        public ExpungedImpl(final long sessionId, final long subjectUid) {
-            super(sessionId);
+        public ExpungedImpl(final long sessionId, final String name, final long subjectUid) {
+            super(sessionId, name);
             this.subjectUid = subjectUid;
         }
 
@@ -138,9 +142,9 @@ public class MailboxEventDispatcher impl
 
         private final Flags newFlags;
 
-        public FlagsUpdatedImpl(final long sessionId, final long subjectUid,
+        public FlagsUpdatedImpl(final long sessionId, final String name, final long subjectUid,
                 final Flags original, final Flags updated) {
-            this(sessionId, subjectUid, updated, isChanged(original, updated,
+            this(sessionId, name, subjectUid, updated, isChanged(original, updated,
                     Flags.Flag.ANSWERED), isChanged(original, updated,
                     Flags.Flag.DELETED), isChanged(original, updated,
                     Flags.Flag.DRAFT), isChanged(original, updated,
@@ -149,12 +153,12 @@ public class MailboxEventDispatcher impl
                     Flags.Flag.SEEN));
         }
 
-        public FlagsUpdatedImpl(final long sessionId, final long subjectUid,
+        public FlagsUpdatedImpl(final long sessionId, final String name, final long subjectUid,
                 final Flags newFlags, boolean answeredUpdated,
                 boolean deletedUpdated, boolean draftUpdated,
                 boolean flaggedUpdated, boolean recentUpdated,
                 boolean seenUpdated) {
-            super(sessionId);
+            super(sessionId, name);
             this.subjectUid = subjectUid;
             this.modifiedFlags = new boolean[NUMBER_OF_SYSTEM_FLAGS];
             this.modifiedFlags[0] = answeredUpdated;
@@ -238,24 +242,24 @@ public class MailboxEventDispatcher impl
         }
     }
 
-    public void mailboxDeleted(long sessionId) {
+    public void mailboxDeleted(long sessionId, String name) {
         final MailboxDeletionEventImpl event = new MailboxDeletionEventImpl(
-                sessionId);
+                sessionId, name);
         event(event);
     }
 
     private static final class MailboxDeletionEventImpl extends
             MailboxListener.MailboxDeletionEvent {
-        public MailboxDeletionEventImpl(final long sessionId) {
-            super(sessionId);
+        public MailboxDeletionEventImpl(final long sessionId, String name) {
+            super(sessionId, name);
         }
     }
 
     private static final class MailboxRenamedEventImpl extends MailboxListener.MailboxRenamed {
         private final String newName;
 
-        public MailboxRenamedEventImpl(final String newName, final long sessionId) {
-            super(sessionId);
+        public MailboxRenamedEventImpl(final String name, final String newName, final long sessionId) {
+            super(sessionId, name);
             this.newName = newName;
         }
 

Modified: james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java (original)
+++ james/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/util/UidChangeTracker.java Tue Apr 27 14:51:34 2010
@@ -42,16 +42,19 @@ public class UidChangeTracker implements
 
     private long lastUid;
 
-    public UidChangeTracker(long lastUid) {
+    private String name;
+
+    public UidChangeTracker(long lastUid, String name) {
         this.lastUid = lastUid;
         eventDispatcher = new MailboxEventDispatcher();
         cache = new TreeMap<Long, Flags>();
+        this.name = name;
     }
 
     public synchronized void expunged(final Collection<Long> uidsExpunged) {
         for (Long uid:uidsExpunged) {
             cache.remove(uid);
-            eventDispatcher.expunged(uid, 0);
+            eventDispatcher.expunged(uid, 0, name);
         }
     }
 
@@ -76,7 +79,7 @@ public class UidChangeTracker implements
                     lastFlags = cachedFlags;
                 }
                 if (!newFlags.equals(lastFlags)) {
-                    eventDispatcher.flagsUpdated(uid, sessionId, lastFlags, newFlags);
+                    eventDispatcher.flagsUpdated(uid, sessionId, name, lastFlags, newFlags);
                 }
                 cache.put(uid, newFlags);
             }
@@ -96,7 +99,7 @@ public class UidChangeTracker implements
 
         for (Iterator<Long> iter = expectedSet.iterator(); iter.hasNext();) {
             long uid = ((Long) iter.next()).longValue();
-            eventDispatcher.expunged(uid, Mailbox.ANONYMOUS_SESSION);
+            eventDispatcher.expunged(uid, Mailbox.ANONYMOUS_SESSION, name);
         }
     }
 
@@ -104,11 +107,11 @@ public class UidChangeTracker implements
         if (flags != null) {
             final Flags cachedFlags = cache.get(uid);
             if (cachedFlags == null || !flags.equals(cachedFlags)) {
-                eventDispatcher.flagsUpdated(uid, Mailbox.ANONYMOUS_SESSION, cachedFlags, flags);
+                eventDispatcher.flagsUpdated(uid, Mailbox.ANONYMOUS_SESSION, name, cachedFlags, flags);
             }
         }
         if (uid > lastUid) {
-            eventDispatcher.added(uid, Mailbox.ANONYMOUS_SESSION);
+            eventDispatcher.added(uid, Mailbox.ANONYMOUS_SESSION, name);
             lastUid = uid;
         }
         cache.put(uid, flags);
@@ -133,10 +136,11 @@ public class UidChangeTracker implements
     }
     
     public void mailboxDeleted(long sessionId) {
-        eventDispatcher.mailboxDeleted(sessionId);
+        eventDispatcher.mailboxDeleted(sessionId, name);
     }
 
     public void reportRenamed(String to) {
-        eventDispatcher.mailboxRenamed(to, Mailbox.ANONYMOUS_SESSION);
+        eventDispatcher.mailboxRenamed(name, to, Mailbox.ANONYMOUS_SESSION);
+        name = to;
     }
 }

Modified: james/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcherFlagsTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcherFlagsTest.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcherFlagsTest.java (original)
+++ james/imap/trunk/mailbox/src/test/java/org/apache/james/imap/mailbox/util/MailboxEventDispatcherFlagsTest.java Tue Apr 27 14:51:34 2010
@@ -48,6 +48,7 @@ public class MailboxEventDispatcherFlags
 
     private Mockery mockery = new JUnit4Mockery();
 
+    private String name = "test";
     @Before
     public void setUp() throws Exception {
         dispatcher = new MailboxEventDispatcher();
@@ -62,7 +63,7 @@ public class MailboxEventDispatcherFlags
    
     @Test
     public void testShouldReturnNoChangesWhenOriginalNull() throws Exception {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, null, new Flags(
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, null, new Flags(
                 Flags.Flag.DELETED));
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -75,7 +76,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldReturnNoChangesWhenSystemFlagsUnchanged() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(
+        dispatcher.flagsUpdated(result.getUid(), sessionId,name, new Flags(
                 Flags.Flag.DELETED), new Flags(Flags.Flag.DELETED));
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -88,7 +89,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowAnsweredAdded() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(),
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(),
                 new Flags(Flags.Flag.ANSWERED));
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -103,7 +104,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowAnsweredRemoved() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(
                 Flags.Flag.ANSWERED), new Flags());
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -118,7 +119,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowDeletedAdded() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(),
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(),
                 new Flags(Flags.Flag.DELETED));
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -133,7 +134,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowDeletedRemoved() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(
                 Flags.Flag.DELETED), new Flags());
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -148,7 +149,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowDraftAdded() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(),
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(),
                 new Flags(Flags.Flag.DRAFT));
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -163,7 +164,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowDraftRemoved() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(
                 Flags.Flag.DRAFT), new Flags());
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -178,7 +179,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowFlaggedAdded() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(),
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(),
                 new Flags(Flags.Flag.FLAGGED));
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -193,7 +194,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowFlaggedRemoved() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(
                 Flags.Flag.FLAGGED), new Flags());
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -208,7 +209,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowRecentAdded() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(),
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(),
                 new Flags(Flags.Flag.RECENT));
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -223,7 +224,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowRecentRemoved() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(
                 Flags.Flag.RECENT), new Flags());
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -238,7 +239,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowSeenAdded() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(),
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(),
                 new Flags(Flags.Flag.SEEN));
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -253,7 +254,7 @@ public class MailboxEventDispatcherFlags
 
     @Test
     public void testShouldShowSeenRemoved() {
-        dispatcher.flagsUpdated(result.getUid(), sessionId, new Flags(
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, new Flags(
                 Flags.Flag.SEEN), new Flags());
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
@@ -276,7 +277,7 @@ public class MailboxEventDispatcherFlags
         updated.add(Flags.Flag.DRAFT);
         updated.add(Flags.Flag.SEEN);
 
-        dispatcher.flagsUpdated(result.getUid(), sessionId, originals, updated);
+        dispatcher.flagsUpdated(result.getUid(), sessionId, name, originals, updated);
         assertEquals(1, collector.events.size());
         assertTrue(collector.events.get(0) instanceof MailboxListener.FlagsUpdated);
         MailboxListener.FlagsUpdated event = (MailboxListener.FlagsUpdated) collector.events

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java Tue Apr 27 14:51:34 2010
@@ -28,6 +28,7 @@ import org.apache.james.imap.mailbox.Mai
 import org.apache.james.imap.mailbox.MailboxNotFoundException;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.StorageException;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.Authenticator;
 import org.apache.james.imap.store.StoreMailbox;
 import org.apache.james.imap.store.StoreMailboxManager;
@@ -47,8 +48,8 @@ public class InMemoryMailboxManager exte
     }
 
     @Override
-    protected StoreMailbox<Long> createMailbox(Mailbox<Long> mailboxRow, MailboxSession session) {
-        final InMemoryStoreMailbox storeMailbox = new InMemoryStoreMailbox((InMemoryMailbox)mailboxRow, session);
+    protected StoreMailbox<Long> createMailbox(MailboxEventDispatcher dispatcher, Mailbox<Long> mailboxRow) {
+        final InMemoryStoreMailbox storeMailbox = new InMemoryStoreMailbox(dispatcher, (InMemoryMailbox)mailboxRow);
         return storeMailbox;
     }
 

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java Tue Apr 27 14:51:34 2010
@@ -36,6 +36,7 @@ import org.apache.james.imap.mailbox.Mai
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.SearchQuery;
 import org.apache.james.imap.mailbox.StorageException;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.MailboxMembershipComparator;
 import org.apache.james.imap.store.StoreMailbox;
 import org.apache.james.imap.store.mail.MessageMapper;
@@ -50,15 +51,15 @@ public class InMemoryStoreMailbox extend
     private Map<Long, MailboxMembership<Long>> membershipByUid;
     private InMemoryMailbox mailbox;
 
-    public InMemoryStoreMailbox(InMemoryMailbox mailbox, MailboxSession session) {
-        super(mailbox,session);
+    public InMemoryStoreMailbox(MailboxEventDispatcher dispatcher, InMemoryMailbox mailbox) {
+        super(dispatcher, mailbox);
         this.mailbox = mailbox;
         this.membershipByUid = new ConcurrentHashMap<Long, MailboxMembership<Long>>(INITIAL_SIZE);
     }
 
     @Override
-    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid) {
-        return new SimpleMailboxMembership(mailboxId, uid, (SimpleMailboxMembership) originalMessage);
+    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid, MailboxSession session) {
+        return new SimpleMailboxMembership(getMailboxId(), uid, (SimpleMailboxMembership) originalMessage);
     }
 
     @Override
@@ -85,7 +86,7 @@ public class InMemoryStoreMailbox extend
             e.printStackTrace();
             byteContent = new byte[0];
         }
-        return new SimpleMailboxMembership(internalDate, uid, size, bodyStartOctet, byteContent, flags, headers, propertyBuilder, mailboxId);
+        return new SimpleMailboxMembership(internalDate, uid, size, bodyStartOctet, byteContent, flags, headers, propertyBuilder, getMailboxId());
 
 
     }
@@ -96,12 +97,12 @@ public class InMemoryStoreMailbox extend
     }
 
     @Override
-    protected Mailbox<Long> getMailboxRow() throws MailboxException {
+    protected Mailbox<Long> getMailboxRow(MailboxSession session) throws MailboxException {
         return mailbox;
     }
 
     @Override
-    protected Mailbox<Long> reserveNextUid() throws MailboxException {
+    protected Mailbox<Long> reserveNextUid(MailboxSession session) throws MailboxException {
         mailbox.consumeUid();
         return mailbox;
     }

Modified: james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/MailboxEventAnalyser.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/MailboxEventAnalyser.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/MailboxEventAnalyser.java (original)
+++ james/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/MailboxEventAnalyser.java Tue Apr 27 14:51:34 2010
@@ -29,6 +29,12 @@ import javax.mail.Flags;
 
 import org.apache.james.imap.mailbox.MailboxListener;
 
+/**
+ * {@link MailboxListener} implementation which will listen for {@link Event} notifications and 
+ * analyze these. It will only act on {@link Event} notifications whiche are send for the registered
+ * Mailbox name
+ *
+ */
 public class MailboxEventAnalyser implements MailboxListener {
 
     private final long sessionId;
@@ -51,15 +57,34 @@ public class MailboxEventAnalyser implem
         this.mailboxName = mailboxName;
     }
     
+    /**
+     * Return the name of the to observing Mailbox 
+     * 
+     * @return name
+     */
     public String getMailboxName() {
         return mailboxName;
     }
 
+    /**
+     * Set the mailbox name of the to observing Mailbox
+     * 
+     * @param mailboxName
+     */
     public void setMailboxName(String mailboxName) {
         this.mailboxName = mailboxName;
     }
 
+    /**
+     * Handle the given {@link Event} if it was fired for the mailbox we are observing
+     * 
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxListener#event(org.apache.james.imap.mailbox.MailboxListener.Event)
+     */
     public void event(Event event) {
+        
+        // Check if the event was for the mailbox we are observing
+        if (event.getMailboxName().equals(mailboxName)) {
         final long eventSessionId = event.getSessionId();
         if (event instanceof MessageEvent) {
             final MessageEvent messageEvent = (MessageEvent) event;
@@ -85,6 +110,7 @@ public class MailboxEventAnalyser implem
             final MailboxRenamed mailboxRenamed = (MailboxRenamed) event;
             setMailboxName(mailboxRenamed.getNewName());
         }
+        }
     }
 
     private boolean interestingFlags(FlagsUpdated updated) {
@@ -103,6 +129,9 @@ public class MailboxEventAnalyser implem
         return result;
     }
 
+    /**
+     * Reset the analyzer
+     */
     public void reset() {
         sizeChanged = false;
         flagUpdateUids.clear();
@@ -150,22 +179,45 @@ public class MailboxEventAnalyser implem
         return isDeletedByOtherSession;
     }
 
+    /**
+     * Return a unmodifiable {@link Collection} of uids which have updated flags
+     * 
+     * @return uids
+     */
+    
     public Collection<Long> flagUpdateUids() {
         return Collections.unmodifiableSet(flagUpdateUids);
     }
 
+    /**
+     * Return a unmodifiable {@link Collection} of uids that where expunged
+     * 
+     * @return uids
+     */
     public Collection<Long> expungedUids() {
         return Collections.unmodifiableSet(expungedUids);
     }
 
+    /**
+     * Return if the analyzer found expunged uids
+     * 
+     * @return hasUids
+     */
     public boolean hasExpungedUids() {
         return !expungedUids.isEmpty();
     }
 
+    /**
+     * Mark the listener as closed. If its marked as closed it will get removed
+     */
     public void close() {
         closed = true;
     }
     
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.mailbox.MailboxListener#isClosed()
+     */
     public boolean isClosed() {
         return closed;
     }

Modified: james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java (original)
+++ james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerAdded.java Tue Apr 27 14:51:34 2010
@@ -27,8 +27,8 @@ public class FakeMailboxListenerAdded ex
 
     public long sessionId;
 
-    public FakeMailboxListenerAdded(long subjectUid, long sessionId) {
-        super(sessionId);
+    public FakeMailboxListenerAdded(long subjectUid, long sessionId, String name) {
+        super(sessionId, name);
         this.subjectUid = subjectUid;
     }
 

Modified: james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java (original)
+++ james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/FakeMailboxListenerFlagsUpdate.java Tue Apr 27 14:51:34 2010
@@ -37,8 +37,8 @@ public class FakeMailboxListenerFlagsUpd
     public Flags newFlags;
 
     public FakeMailboxListenerFlagsUpdate(long subjectUid, Flags newFlags,
-            long sessionId) {
-        super(sessionId);
+            long sessionId, String name) {
+        super(sessionId, name);
         this.subjectUid = subjectUid;
         this.newFlags = newFlags;
     }

Modified: james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java (original)
+++ james/imap/trunk/processor/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java Tue Apr 27 14:51:34 2010
@@ -37,15 +37,15 @@ public class MailboxEventAnalyserTest {
     private static final long BASE_SESSION_ID = 99;
 
     private MailboxEventAnalyser analyser;
-    
+    private String name = "Mailbox Name";
     @Before
     public void setUp() throws Exception {
-        analyser = new MailboxEventAnalyser(BASE_SESSION_ID, "Mailbox Name");
+        analyser = new MailboxEventAnalyser(BASE_SESSION_ID, name);
     }
 
     @Test
     public void testShouldBeNoSizeChangeOnOtherEvent() throws Exception {
-        final MailboxListener.Event event = new MailboxListener.Event(0) {};
+        final MailboxListener.Event event = new MailboxListener.Event(0, name) {};
       
         analyser.event(event);
         assertFalse(analyser.isSizeChanged());
@@ -53,13 +53,13 @@ public class MailboxEventAnalyserTest {
 
     @Test
     public void testShouldBeNoSizeChangeOnAdded() throws Exception {
-        analyser.event(new FakeMailboxListenerAdded(78, 11));
+        analyser.event(new FakeMailboxListenerAdded(78, 11, name));
         assertTrue(analyser.isSizeChanged());
     }
 
     @Test
     public void testShouldNoSizeChangeAfterReset() throws Exception {
-        analyser.event(new FakeMailboxListenerAdded(99, 11));
+        analyser.event(new FakeMailboxListenerAdded(99, 11, name));
         analyser.reset();
         assertFalse(analyser.isSizeChanged());
     }
@@ -67,7 +67,7 @@ public class MailboxEventAnalyserTest {
     @Test
     public void testShouldNotSetUidWhenNoSystemFlagChange() throws Exception {
         final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(
-                90, new Flags(), 11);
+                90, new Flags(), 11, name);
         analyser.event(update);
         assertNotNull(analyser.flagUpdateUids());
         assertFalse(analyser.flagUpdateUids().iterator().hasNext());
@@ -77,7 +77,7 @@ public class MailboxEventAnalyserTest {
     public void testShouldSetUidWhenSystemFlagChange() throws Exception {
         final long uid = 900L;
         final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(
-                uid, new Flags(), 11);
+                uid, new Flags(), 11, name);
         update.flags.add(Flags.Flag.ANSWERED);
         analyser.event(update);
         final Iterator<Long> iterator = analyser.flagUpdateUids().iterator();
@@ -91,7 +91,7 @@ public class MailboxEventAnalyserTest {
     public void testShouldClearFlagUidsUponReset() throws Exception {
         final long uid = 900L;
         final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(
-                uid, new Flags(), 11);
+                uid, new Flags(), 11, name);
         update.flags.add(Flags.Flag.ANSWERED);
         analyser.event(update);
         analyser.reset();
@@ -104,7 +104,7 @@ public class MailboxEventAnalyserTest {
             throws Exception {
         final long uid = 900L;
         final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(
-                uid, new Flags(), 11);
+                uid, new Flags(), 11, name);
         update.flags.add(Flags.Flag.ANSWERED);
         analyser.setSilentFlagChanges(true);
         analyser.event(update);
@@ -119,7 +119,7 @@ public class MailboxEventAnalyserTest {
     public void testShouldNotSetUidWhenSystemFlagChangeSameSessionInSilentMode()
             throws Exception {
         final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(
-                345, new Flags(), BASE_SESSION_ID);
+                345, new Flags(), BASE_SESSION_ID, name);
         update.flags.add(Flags.Flag.ANSWERED);
         analyser.setSilentFlagChanges(true);
         analyser.event(update);
@@ -131,7 +131,7 @@ public class MailboxEventAnalyserTest {
     @Test
     public void testShouldNotSetUidWhenOnlyRecentFlagUpdated() throws Exception {
         final FakeMailboxListenerFlagsUpdate update = new FakeMailboxListenerFlagsUpdate(
-                886, new Flags(), BASE_SESSION_ID);
+                886, new Flags(), BASE_SESSION_ID ,name);
         update.flags.add(Flags.Flag.RECENT);
         analyser.event(update);
         final Iterator<Long> iterator = analyser.flagUpdateUids().iterator();

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java Tue Apr 27 14:51:34 2010
@@ -51,7 +51,7 @@ import org.apache.james.imap.mailbox.Mes
 import org.apache.james.imap.mailbox.MessageResult;
 import org.apache.james.imap.mailbox.SearchQuery;
 import org.apache.james.imap.mailbox.MessageResult.FetchGroup;
-import org.apache.james.imap.mailbox.util.UidChangeTracker;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.mailbox.util.UidRange;
 import org.apache.james.imap.store.mail.MessageMapper;
 import org.apache.james.imap.store.mail.model.Header;
@@ -64,8 +64,12 @@ import org.apache.james.mime4j.descripto
 import org.apache.james.mime4j.parser.MimeEntityConfig;
 import org.apache.james.mime4j.parser.MimeTokenStream;
 
+import com.sun.mail.imap.protocol.MessageSet;
+
 /**
- * Abstract base class for {@link org.apache.james.imap.mailbox.Mailbox} implementations
+ * Abstract base class for {@link org.apache.james.imap.mailbox.Mailbox} implementations.
+ * 
+ * This class provides a high-level api, and is most times the best to just extend
  * 
  *
  */
@@ -75,42 +79,32 @@ public abstract class StoreMailbox<Id> i
 
     private static final int INITIAL_SIZE_HEADERS = 32;
 
-    protected final Id mailboxId;
-
-    private final UidChangeTracker tracker;
-    private final MailboxSession session;
+    private final Id mailboxId;
+    
+    private MailboxEventDispatcher dispatcher;
     
-    public StoreMailbox(final Mailbox<Id> mailbox, final MailboxSession session) {
+    public StoreMailbox(final MailboxEventDispatcher dispatcher, final Mailbox<Id> mailbox) {
         this.mailboxId = mailbox.getMailboxId();
-        this.tracker = new UidChangeTracker(mailbox.getLastUid());
-        this.session = session;
+        this.dispatcher = dispatcher;
     }
 
     /**
-     * Return the {@link UidChangeTracker} which is used for the {@link Mailbox}
+     * Return the {@link MailboxEventDispatcher} for this Mailbox
      * 
-     * @return tracker
+     * @return dispatcher
      */
-    protected UidChangeTracker getUidChangeTracker() {
-        return tracker;
+    protected MailboxEventDispatcher getDispatcher() {
+        return dispatcher;
     }
     
     /**
-     * Return the {@link MailboxSession} for this {@link StoreMailbox}
-     * 
-     * @return session
-     */
-    protected MailboxSession getMailboxSession() {
-        return session;
-    }
-    /**
      * Copy the given {@link MailboxMembership} to a new instance with the given uid
      * 
      * @param originalMessage
      * @param uid
      * @return membershipCopy
      */
-    protected abstract MailboxMembership<Id> copyMessage(MailboxMembership<Id> originalMessage, long uid) throws MailboxException;
+    protected abstract MailboxMembership<Id> copyMessage(MailboxMembership<Id> originalMessage, long uid, MailboxSession session) throws MailboxException;
     
     /**
      * Create a new {@link MessageMapper} to use
@@ -120,7 +114,14 @@ public abstract class StoreMailbox<Id> i
     protected abstract MessageMapper<Id> createMessageMapper(MailboxSession session) throws MailboxException;
     
     
-    protected abstract Mailbox<Id> getMailboxRow() throws MailboxException;
+    /**
+     * Return the underlying {@link Mailbox}
+     * 
+     * @param session
+     * @return mailbox
+     * @throws MailboxException
+     */
+    protected abstract Mailbox<Id> getMailboxRow(MailboxSession session) throws MailboxException;
 
     /**
      * Return the Id of the wrapped {@link Mailbox}
@@ -136,7 +137,7 @@ public abstract class StoreMailbox<Id> i
      * @see org.apache.james.imap.mailbox.Mailbox#getMessageCount(org.apache.james.imap.mailbox.MailboxSession)
      */
     public int getMessageCount(MailboxSession mailboxSession) throws MailboxException {
-        final MessageMapper<Id> messageMapper = createMessageMapper(session);
+        final MessageMapper<Id> messageMapper = createMessageMapper(mailboxSession);
         return (int) messageMapper.countMessagesInMailbox();
     }
 
@@ -148,7 +149,7 @@ public abstract class StoreMailbox<Id> i
             MailboxSession mailboxSession, boolean isRecent, Flags flagsToBeSet)
     throws MailboxException {
 
-        final Mailbox<Id> mailbox = reserveNextUid();
+        final Mailbox<Id> mailbox = reserveNextUid(mailboxSession);
         if (mailbox == null) {
             throw new MailboxNotFoundException("Mailbox has been deleted");
         } else {
@@ -276,7 +277,7 @@ public abstract class StoreMailbox<Id> i
                 }
                 
                 final MailboxMembership<Id> message = createMessage(internalDate, uid, size, bodyStartOctet, new FileInputStream(file), flags, headers, propertyBuilder);
-                final MessageMapper<Id> mapper = createMessageMapper(session);
+                final MessageMapper<Id> mapper = createMessageMapper(mailboxSession);
 
                 mapper.execute(new TransactionalMapper.Transaction() {
 
@@ -285,7 +286,8 @@ public abstract class StoreMailbox<Id> i
                     }
                     
                 });
-                tracker.found(uid, message.createFlags());
+                dispatcher.added(uid, mailboxSession.getSessionId(), getMailboxRow(mailboxSession).getName());
+                //tracker.found(uid, message.createFlags());
                 return uid;
             } catch (IOException e) {
                 e.printStackTrace();
@@ -382,7 +384,7 @@ public abstract class StoreMailbox<Id> i
      * @return mailbox
      * @throws MailboxException
      */
-    protected abstract Mailbox<Id> reserveNextUid() throws  MailboxException;
+    protected abstract Mailbox<Id> reserveNextUid(MailboxSession session) throws  MailboxException;
 
     /*
      * (non-Javadoc)
@@ -391,7 +393,7 @@ public abstract class StoreMailbox<Id> i
     public Iterator<MessageResult> getMessages(final MessageRange set, FetchGroup fetchGroup,
             MailboxSession mailboxSession) throws MailboxException {
         UidRange range = uidRangeForMessageSet(set);
-        final MessageMapper<Id> messageMapper = createMessageMapper(session);
+        final MessageMapper<Id> messageMapper = createMessageMapper(mailboxSession);
         final List<MailboxMembership<Id>> rows = new ArrayList<MailboxMembership<Id>>(messageMapper.findInMailbox(set));
         return getMessages(fetchGroup, range, rows);
     }
@@ -402,7 +404,6 @@ public abstract class StoreMailbox<Id> i
             flagsByIndex.put(member.getUid(), member.createFlags());
         }
         final ResultIterator<Id> results = getResults(result, messages);
-        tracker.found(range, flagsByIndex);
         return results;
     }
 
@@ -431,7 +432,7 @@ public abstract class StoreMailbox<Id> i
     }
 
     private long[] recent(final boolean reset, MailboxSession mailboxSession) throws MailboxException {
-        final MessageMapper<Id> mapper = createMessageMapper(session);
+        final MessageMapper<Id> mapper = createMessageMapper(mailboxSession);
         final List<Long> results = new ArrayList<Long>();
 
         mapper.execute(new TransactionalMapper.Transaction() {
@@ -455,14 +456,13 @@ public abstract class StoreMailbox<Id> i
 
     private Long getFirstUnseen(MailboxSession mailboxSession) throws MailboxException {
         try {
-            final MessageMapper<Id> messageMapper = createMessageMapper(session);
+            final MessageMapper<Id> messageMapper = createMessageMapper(mailboxSession);
             final List<MailboxMembership<Id>> members = messageMapper.findUnseenMessagesInMailbox();
             final Iterator<MailboxMembership<Id>> it = members.iterator();
             final Long result;
             if (it.hasNext()) {
                 final MailboxMembership<Id> member = it.next();
                 result = member.getUid();
-                tracker.found(result, member.createFlags());
             } else {
                 result = null;
             }
@@ -473,7 +473,7 @@ public abstract class StoreMailbox<Id> i
     }
 
     private int getUnseenCount(MailboxSession mailboxSession) throws MailboxException {
-        final MessageMapper<Id> messageMapper = createMessageMapper(session);
+        final MessageMapper<Id> messageMapper = createMessageMapper(mailboxSession);
         final int count = (int) messageMapper.countUnseenMessagesInMailbox();
         return count;
     }
@@ -483,12 +483,12 @@ public abstract class StoreMailbox<Id> i
      * @see org.apache.james.imap.mailbox.Mailbox#expunge(org.apache.james.imap.mailbox.MessageRange, org.apache.james.imap.mailbox.MailboxSession)
      */
     public Iterator<Long> expunge(MessageRange set, MailboxSession mailboxSession) throws MailboxException {
-        return doExpunge(set);
+        return doExpunge(set, mailboxSession);
     }
 
-    private Iterator<Long> doExpunge(final MessageRange set)
+    private Iterator<Long> doExpunge(final MessageRange set, MailboxSession mailboxSession)
     throws MailboxException {
-        final MessageMapper<Id> mapper = createMessageMapper(session);
+        final MessageMapper<Id> mapper = createMessageMapper(mailboxSession);
         final Collection<Long> uids = new TreeSet<Long>();
         
         mapper.execute(new TransactionalMapper.Transaction() {
@@ -503,7 +503,10 @@ public abstract class StoreMailbox<Id> i
             
         });
         
-        tracker.expunged(uids);
+        Iterator<Long> uidIt = uids.iterator();
+        while(uidIt.hasNext()) {
+            dispatcher.expunged(uidIt.next(), mailboxSession.getSessionId(), getMailboxRow(mailboxSession).getName());
+        }
         return uids.iterator();
     }
 
@@ -518,7 +521,7 @@ public abstract class StoreMailbox<Id> i
 
     private Map<Long, Flags> doSetFlags(final Flags flags, final boolean value, final boolean replace,
             final MessageRange set, final MailboxSession mailboxSession) throws MailboxException {
-        final MessageMapper<Id> mapper = createMessageMapper(session);
+        final MessageMapper<Id> mapper = createMessageMapper(mailboxSession);
         final SortedMap<Long, Flags> newFlagsByUid = new TreeMap<Long, Flags>();
         final Map<Long, Flags> originalFlagsByUid = new HashMap<Long, Flags>(INITIAL_SIZE_FLAGS);
         mapper.execute(new TransactionalMapper.Transaction(){
@@ -545,21 +548,26 @@ public abstract class StoreMailbox<Id> i
             
         });
        
-        tracker.flagsUpdated(newFlagsByUid, originalFlagsByUid, mailboxSession.getSessionId());
+        Iterator<Long> it = newFlagsByUid.keySet().iterator();
+        while (it.hasNext()) {
+            Long uid = it.next();
+            dispatcher.flagsUpdated(uid, mailboxSession.getSessionId(), getMailboxRow(mailboxSession).getName(), originalFlagsByUid.get(uid), newFlagsByUid.get(uid));
+
+        }
         return newFlagsByUid;
     }
 
     public void addListener(MailboxListener listener) throws MailboxException {
-        tracker.addMailboxListener(listener);
+        dispatcher.addMailboxListener(listener);
     }
 
     private long getUidValidity(MailboxSession mailboxSession) throws MailboxException {
-        final long result = getMailboxRow().getUidValidity();
+        final long result = getMailboxRow(mailboxSession).getUidValidity();
         return result;
     }
 
     private long getUidNext(MailboxSession mailboxSession) throws MailboxException {
-        Mailbox<Id> mailbox = getMailboxRow();
+        Mailbox<Id> mailbox = getMailboxRow(mailboxSession);
         if (mailbox == null) {
             throw new MailboxNotFoundException("Mailbox has been deleted");
         } else {
@@ -573,7 +581,7 @@ public abstract class StoreMailbox<Id> i
      * @see org.apache.james.imap.mailbox.Mailbox#search(org.apache.james.imap.mailbox.SearchQuery, org.apache.james.imap.mailbox.MailboxSession)
      */
     public Iterator<Long> search(SearchQuery query, MailboxSession mailboxSession) throws MailboxException {
-        final MessageMapper<Id> messageMapper = createMessageMapper(session);
+        final MessageMapper<Id> messageMapper = createMessageMapper(mailboxSession);
         final List<MailboxMembership<Id>> members = messageMapper.searchMailbox(query);
         final Set<Long> uids = new TreeSet<Long>();
         for (MailboxMembership<Id> member:members) {
@@ -596,16 +604,16 @@ public abstract class StoreMailbox<Id> i
         return uids.iterator();
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.mailbox.Mailbox#isWriteable()
+
+    /**
+     * This mailbox is writable
      */
     public boolean isWriteable() {
         return true;
     }
     
 
-    private void copy(final List<MailboxMembership<Id>> originalRows, MailboxSession session) throws MailboxException {
+    private void copy(final List<MailboxMembership<Id>> originalRows, final MailboxSession session) throws MailboxException {
         try {
             final List<MailboxMembership<Id>> copiedRows = new ArrayList<MailboxMembership<Id>>();
             final MessageMapper<Id> mapper = createMessageMapper(session);
@@ -614,10 +622,10 @@ public abstract class StoreMailbox<Id> i
                 public void run() throws MailboxException {
                     for (MailboxMembership<Id> originalMessage:originalRows) {
 
-                        final Mailbox<Id> mailbox = reserveNextUid();
+                        final Mailbox<Id> mailbox = reserveNextUid(session );
                         if (mailbox != null) {
                             long uid = mailbox.getLastUid();
-                            final MailboxMembership<Id> newRow = copyMessage(originalMessage, uid);
+                            final MailboxMembership<Id> newRow = copyMessage(originalMessage, uid, session);
                             mapper.save(newRow);
                             copiedRows.add(newRow);
                         }
@@ -629,7 +637,7 @@ public abstract class StoreMailbox<Id> i
             
             // Wait until commit before issuing events
             for (MailboxMembership<Id> newMember:copiedRows) {
-                tracker.found(newMember.getUid(), newMember.createFlags());
+                dispatcher.added(newMember.getUid(), session.getSessionId(), getMailboxRow(session).getName());
             }
             
         } catch (MessagingException e) {
@@ -637,6 +645,14 @@ public abstract class StoreMailbox<Id> i
         }
     }
 
+    /**
+     * Copy the {@link MessageSet} to the {@link StoreMailbox}
+     * 
+     * @param set
+     * @param toMailbox
+     * @param session
+     * @throws MailboxException
+     */
     public void copyTo(MessageRange set, StoreMailbox<Id> toMailbox, MailboxSession session) throws MailboxException {
         try {
             final MessageMapper<Id> mapper = createMessageMapper(session);
@@ -650,14 +666,6 @@ public abstract class StoreMailbox<Id> i
         }
     }
     
-    public void deleted(MailboxSession session) {
-        tracker.mailboxDeleted(session.getSessionId());
-    }
-
-    public void reportRenamed(String to) {
-        tracker.reportRenamed(to);
-    }
-    
     /**
      * @see {@link Mailbox#getMetaData(boolean, MailboxSession, FetchGroup)}
      */

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java Tue Apr 27 14:51:34 2010
@@ -45,11 +45,21 @@ import org.apache.james.imap.mailbox.Sta
 import org.apache.james.imap.mailbox.StorageException;
 import org.apache.james.imap.mailbox.SubscriptionException;
 import org.apache.james.imap.mailbox.MailboxMetaData.Selectability;
+import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.mailbox.util.SimpleMailboxMetaData;
 import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.transaction.TransactionalMapper;
 
+/**
+ * This abstract base class of an {@link MailboxManager} implementation provides a high-level api for writing your own
+ * {@link MailboxManager} implementation. If you plan to write your own {@link MailboxManager} its most times so easiest 
+ * to extend just this class.
+ * 
+ * If you need a more low-level api just implement {@link MailboxManager} directly
+ *
+ * @param <Id>
+ */
 public abstract class StoreMailboxManager<Id> extends AbstractLogEnabled implements MailboxManager {
     public static final String USER_NAMESPACE_PREFIX = "#mail";
     
@@ -58,7 +68,8 @@ public abstract class StoreMailboxManage
     private final static Random random = new Random();
 
     protected final Map<String, StoreMailbox<Id>> mailboxes;
-
+    private final MailboxEventDispatcher dispatcher = new MailboxEventDispatcher();
+    
     private final Authenticator authenticator;    
     private final Subscriber subscriber;    
     
@@ -84,7 +95,7 @@ public abstract class StoreMailboxManage
      * @param mailboxRow
      * @return storeMailbox
      */
-    protected abstract StoreMailbox<Id> createMailbox(Mailbox<Id> mailboxRow, MailboxSession session);
+    protected abstract StoreMailbox<Id> createMailbox(MailboxEventDispatcher dispatcher, Mailbox<Id> mailboxRow);
     
     /**
      * Create the MailboxMapper which should get used 
@@ -132,7 +143,7 @@ public abstract class StoreMailboxManage
 
                 StoreMailbox<Id> result = (StoreMailbox<Id>) mailboxes.get(mailboxName);
                 if (result == null) {
-                    result = createMailbox(mailboxRow, session);
+                    result = createMailbox(dispatcher, mailboxRow);
                     mailboxes.put(mailboxName, result);
                     
                     // store the mailbox in the session so we can cleanup things later
@@ -211,8 +222,9 @@ public abstract class StoreMailboxManage
             
             final StoreMailbox<Id> storeMailbox = mailboxes.remove(mailboxName);
             if (storeMailbox != null) {
-                storeMailbox.deleted(session);
+                //storeMailbox.deleted(session);
             }
+            dispatcher.mailboxDeleted(session.getSessionId(), mailboxName);
         }
     }
 
@@ -242,7 +254,7 @@ public abstract class StoreMailboxManage
                     mailbox.setName(to);
                     mapper.save(mailbox);
 
-                    changeMailboxName(from, to);
+                    changeMailboxName(from, to, session);
 
                     // rename submailbox
                     final List<Mailbox<Id>> subMailboxes = mapper.findMailboxWithNameLike(from + delimiter + "%");
@@ -252,7 +264,7 @@ public abstract class StoreMailboxManage
                         sub.setName(subNewName);
                         mapper.save(sub);
 
-                        changeMailboxName(subOriginalName, subNewName);
+                        changeMailboxName(subOriginalName, subNewName, session);
 
                         if (log.isDebugEnabled()) log.debug("Rename mailbox sub-mailbox " + subOriginalName + " to "
                                 + subNewName);
@@ -277,12 +289,13 @@ public abstract class StoreMailboxManage
      * @param from not null
      * @param to not null
      */
-    private void changeMailboxName(String from, String to) {
+    private void changeMailboxName(String from, String to, MailboxSession session) {
         final StoreMailbox<Id> jpaMailbox = mailboxes.remove(from);
         if (jpaMailbox != null) {
-            jpaMailbox.reportRenamed(to);
-            mailboxes.put(to, jpaMailbox);
+            //jpaMailbox.reportRenamed(to);
         }
+        mailboxes.put(to, jpaMailbox);
+        dispatcher.mailboxRenamed(from, to, session.getSessionId());
     }
 
     /*

Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java (original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java Tue Apr 27 14:51:34 2010
@@ -94,7 +94,7 @@ public class TorqueMailbox implements Ma
     TorqueMailbox(final MailboxRow mailboxRow, final ReentrantReadWriteLock lock) {
         this.searches = new MessageSearches();
         this.mailboxRow = mailboxRow;
-        this.tracker = new UidChangeTracker(mailboxRow.getLastUid());
+        this.tracker = new UidChangeTracker(mailboxRow.getLastUid(), mailboxRow.getName());
         this.lock = lock;
     }
 
@@ -806,7 +806,7 @@ public class TorqueMailbox implements Ma
         tracker.mailboxDeleted(session.getSessionId());
     }
 
-    public void reportRenamed(MailboxRow mailboxRow) {
+    public void reportRenamed(String from, MailboxRow mailboxRow) {
         tracker.reportRenamed(mailboxRow.getName());
         this.mailboxRow = mailboxRow;
     }

Modified: james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java?rev=938484&r1=938483&r2=938484&view=diff
==============================================================================
--- james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java (original)
+++ james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailboxManager.java Tue Apr 27 14:51:34 2010
@@ -243,7 +243,7 @@ public class TorqueMailboxManager implem
     private void changeMailboxName(String from, String to, final MailboxRow mr) {
         TorqueMailbox torqueMailbox = (TorqueMailbox) mailboxes.remove(from);
         if (torqueMailbox != null) {
-            torqueMailbox.reportRenamed(mr);
+            torqueMailbox.reportRenamed(from, mr);
             mailboxes.put(to, torqueMailbox);
         }
     }



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