MAILBOX-354 MailboxListeners should be registered by MailboxId It was previously done on MailboxPath, which is mutable.
Mutability leads to significantly harder code when it comes to mailbox renames. Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d9bcebc7 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d9bcebc7 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d9bcebc7 Branch: refs/heads/master Commit: d9bcebc7dd546bd5f11f3d9b496491e7c9042fe2 Parents: d22fe0e Author: Benoit Tellier <btell...@linagora.com> Authored: Fri Nov 30 10:52:11 2018 +0700 Committer: Benoit Tellier <btell...@linagora.com> Committed: Tue Dec 4 15:47:32 2018 +0700 ---------------------------------------------------------------------- .../james/mailbox/MailboxListenerSupport.java | 9 +- .../james/mailbox/MailboxManagerStressTest.java | 7 +- .../mailbox/store/StoreMailboxManager.java | 8 +- .../event/DefaultDelegatingMailboxListener.java | 21 ++-- .../store/event/MailboxListenerRegistry.java | 24 ++--- .../DefaultDelegatingMailboxListenerTest.java | 61 +++-------- .../event/MailboxListenerRegistryTest.java | 100 +++++++------------ .../james/imap/processor/IdleProcessor.java | 4 +- .../processor/base/SelectedMailboxImpl.java | 7 +- .../processor/base/SelectedMailboxImplTest.java | 8 +- 10 files changed, 93 insertions(+), 156 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java index 1f5e35d..f76b70f 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListenerSupport.java @@ -20,6 +20,7 @@ package org.apache.james.mailbox; import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; /** @@ -37,7 +38,7 @@ public interface MailboxListenerSupport { * everyone has removed itself. * </p> * - * @param mailboxPath + * @param mailboxId * not null * @param listener * not null @@ -45,17 +46,17 @@ public interface MailboxListenerSupport { * not null * @throws MailboxException */ - void addListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException; + void addListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) throws MailboxException; /** * Remove the {@link MailboxListener} * - * @param mailboxPath + * @param mailboxId * @param listner * @param session * @throws MailboxException */ - void removeListener(MailboxPath mailboxPath, MailboxListener listner, MailboxSession session) throws MailboxException; + void removeListener(MailboxId mailboxId, MailboxListener listner, MailboxSession session) throws MailboxException; /** * Add a {@link MailboxListener} which get fired for ever http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java index 8f41eb7..9f13dec 100644 --- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java @@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.nio.charset.StandardCharsets; import java.util.Collection; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.CountDownLatch; @@ -32,6 +33,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.ComposedMessageId; +import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mime4j.dom.Message; import org.junit.Test; @@ -61,9 +63,8 @@ public abstract class MailboxManagerStressTest { MailboxSession session = mailboxManager.createSystemSession(username); mailboxManager.startProcessingRequest(session); final MailboxPath path = MailboxPath.forUser(username, "INBOX"); - mailboxManager.createMailbox(path, session); - mailboxManager.addListener(path, new MailboxListener() { - + Optional<MailboxId> mailboxId = mailboxManager.createMailbox(path, session); + mailboxManager.addListener(mailboxId.get(), new MailboxListener() { @Override public ListenerType getType() { return ListenerType.MAILBOX; http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java index 7eb53d8..63c30ef 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java @@ -768,8 +768,8 @@ public class StoreMailboxManager implements MailboxManager { } @Override - public void addListener(MailboxPath path, MailboxListener listener, MailboxSession session) throws MailboxException { - delegatingListener.addListener(path, listener, session); + public void addListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) throws MailboxException { + delegatingListener.addListener(mailboxId, listener, session); } /** @@ -803,8 +803,8 @@ public class StoreMailboxManager implements MailboxManager { } @Override - public void removeListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException { - delegatingListener.removeListener(mailboxPath, listener, session); + public void removeListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) throws MailboxException { + delegatingListener.removeListener(mailboxId, listener, session); } http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java index a380304..59b91cc 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java @@ -27,14 +27,14 @@ import org.apache.james.mailbox.Event; import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.MailboxId; import org.apache.james.metrics.api.NoopMetricFactory; import com.google.common.annotations.VisibleForTesting; /** * Receive a {@link org.apache.james.mailbox.MailboxListener.MailboxEvent} and delegate it to an other - * {@link MailboxListener} depending on the registered name + * {@link MailboxListener} depending on the registered mailboxId * * This is a mono instance Thread safe implementation for DelegatingMailboxListener */ @@ -61,11 +61,11 @@ public class DefaultDelegatingMailboxListener implements DelegatingMailboxListen } @Override - public void addListener(MailboxPath path, MailboxListener listener, MailboxSession session) throws MailboxException { + public void addListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) throws MailboxException { if (listener.getType() != ListenerType.MAILBOX) { throw new MailboxException(listener.getClass().getCanonicalName() + " registred on specific MAILBOX operation while its listener type was " + listener.getType()); } - registry.addListener(path, listener); + registry.addListener(mailboxId, listener); } @Override @@ -77,12 +77,12 @@ public class DefaultDelegatingMailboxListener implements DelegatingMailboxListen } @Override - public void removeListener(MailboxPath mailboxPath, MailboxListener listener, MailboxSession session) throws MailboxException { - registry.removeListener(mailboxPath, listener); + public void removeListener(MailboxId mailboxId, MailboxListener listener, MailboxSession session) { + registry.removeListener(mailboxId, listener); } @Override - public void removeGlobalListener(MailboxListener listener, MailboxSession session) throws MailboxException { + public void removeGlobalListener(MailboxListener listener, MailboxSession session) { registry.removeGlobalListener(listener); } @@ -95,12 +95,9 @@ public class DefaultDelegatingMailboxListener implements DelegatingMailboxListen } private void mailboxEvent(MailboxEvent mailboxEvent) { - Collection<MailboxListener> listenerSnapshot = registry.getLocalMailboxListeners(mailboxEvent.getMailboxPath()); + Collection<MailboxListener> listenerSnapshot = registry.getLocalMailboxListeners(mailboxEvent.getMailboxId()); if (mailboxEvent instanceof MailboxDeletion && listenerSnapshot.size() > 0) { - registry.deleteRegistryFor(mailboxEvent.getMailboxPath()); - } else if (mailboxEvent instanceof MailboxRenamed && listenerSnapshot.size() > 0) { - MailboxRenamed renamed = (MailboxRenamed) mailboxEvent; - registry.handleRename(renamed.getMailboxPath(), renamed.getNewPath()); + registry.deleteRegistryFor(mailboxEvent.getMailboxId()); } deliverEventToMailboxListeners(mailboxEvent, listenerSnapshot); } http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java index d29caff..83461e6 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; import org.apache.james.mailbox.MailboxListener; -import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.MailboxId; import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; @@ -32,7 +32,7 @@ import com.google.common.collect.Multimaps; public class MailboxListenerRegistry { - private final Multimap<MailboxPath, MailboxListener> listeners; + private final Multimap<MailboxId, MailboxListener> listeners; private final ConcurrentLinkedQueue<MailboxListener> globalListeners; public MailboxListenerRegistry() { @@ -40,36 +40,32 @@ public class MailboxListenerRegistry { this.listeners = Multimaps.synchronizedMultimap(HashMultimap.create()); } - public void addListener(MailboxPath path, MailboxListener listener) { - listeners.put(path, listener); + public void addListener(MailboxId mailboxId, MailboxListener listener) { + listeners.put(mailboxId, listener); } public void addGlobalListener(MailboxListener listener) { globalListeners.add(listener); } - public void removeListener(MailboxPath mailboxPath, MailboxListener listener) { - listeners.remove(mailboxPath, listener); + public void removeListener(MailboxId mailboxId, MailboxListener listener) { + listeners.remove(mailboxId, listener); } public void removeGlobalListener(MailboxListener listener) { globalListeners.remove(listener); } - public List<MailboxListener> getLocalMailboxListeners(MailboxPath path) { - return ImmutableList.copyOf(listeners.get(path)); + public List<MailboxListener> getLocalMailboxListeners(MailboxId mailboxId) { + return ImmutableList.copyOf(listeners.get(mailboxId)); } public List<MailboxListener> getGlobalListeners() { return ImmutableList.copyOf(globalListeners); } - public void deleteRegistryFor(MailboxPath path) { - listeners.removeAll(path); - } - - public void handleRename(MailboxPath oldName, MailboxPath newName) { - listeners.putAll(newName, listeners.removeAll(oldName)); + public void deleteRegistryFor(MailboxId mailboxId) { + listeners.removeAll(mailboxId); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java index 190e0b2..c9a411a 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListenerTest.java @@ -45,6 +45,7 @@ public class DefaultDelegatingMailboxListenerTest { private static final MailboxPath MAILBOX_PATH = new MailboxPath("namespace", "user", "name"); private static final MailboxPath OTHER_MAILBOX_PATH = new MailboxPath("namespace", "other", "name"); private static final MailboxId MAILBOX_ID = TestId.of(100); + private static final MailboxId OTHER_MAILBOX_ID = TestId.of(42); private DefaultDelegatingMailboxListener defaultDelegatingMailboxListener; private EventCollector mailboxEventCollector; @@ -57,7 +58,7 @@ public class DefaultDelegatingMailboxListenerTest { eachNodeEventCollector = new EventCollector(MailboxListener.ListenerType.EACH_NODE); onceEventCollector = new EventCollector(MailboxListener.ListenerType.ONCE); defaultDelegatingMailboxListener = new DefaultDelegatingMailboxListener(); - defaultDelegatingMailboxListener.addListener(MAILBOX_PATH, mailboxEventCollector, null); + defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxEventCollector, null); defaultDelegatingMailboxListener.addGlobalListener(onceEventCollector, null); defaultDelegatingMailboxListener.addGlobalListener(eachNodeEventCollector, null); } @@ -65,13 +66,13 @@ public class DefaultDelegatingMailboxListenerTest { @Test(expected = MailboxException.class) public void addListenerShouldThrowOnEACH_NODEListenerType() throws Exception { MailboxListener mailboxListener = new EventCollector(MailboxListener.ListenerType.EACH_NODE); - defaultDelegatingMailboxListener.addListener(MAILBOX_PATH, mailboxListener, null); + defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxListener, null); } @Test(expected = MailboxException.class) public void addListenerShouldThrowOnONCEListenerType() throws Exception { MailboxListener mailboxListener = new EventCollector(MailboxListener.ListenerType.ONCE); - defaultDelegatingMailboxListener.addListener(MAILBOX_PATH, mailboxListener, null); + defaultDelegatingMailboxListener.addListener(MAILBOX_ID, mailboxListener, null); } @Test(expected = MailboxException.class) @@ -81,7 +82,7 @@ public class DefaultDelegatingMailboxListenerTest { } @Test - public void eventShouldWork() throws Exception { + public void eventShouldWork() { MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {}; defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).containsExactly(event); @@ -90,8 +91,8 @@ public class DefaultDelegatingMailboxListenerTest { } @Test - public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() throws Exception { - MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH, MAILBOX_ID) {}; + public void eventShouldOnlyTriggerMAILBOXListenerRelatedToTheEvent() { + MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH, OTHER_MAILBOX_ID) {}; defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).isEmpty(); assertThat(eachNodeEventCollector.getEvents()).containsExactly(event); @@ -99,39 +100,7 @@ public class DefaultDelegatingMailboxListenerTest { } @Test - public void mailboxRenamedEventShouldUnregisterMAILBOXFromTheirPreviousPath() throws Exception { - MailboxListener.MailboxRenamed event = new MailboxListener.MailboxRenamed(null, MAILBOX_PATH, MAILBOX_ID) { - @Override - public MailboxPath getNewPath() { - return OTHER_MAILBOX_PATH; - } - }; - defaultDelegatingMailboxListener.event(event); - MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {}; - defaultDelegatingMailboxListener.event(secondEvent); - assertThat(mailboxEventCollector.getEvents()).containsExactly(event); - assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent); - assertThat(onceEventCollector.getEvents()).containsExactly(event, secondEvent); - } - - @Test - public void mailboxRenamedEventShouldRegisterMAILBOXToTheirNewPath() throws Exception { - MailboxListener.MailboxRenamed event = new MailboxListener.MailboxRenamed(null, MAILBOX_PATH, MAILBOX_ID) { - @Override - public MailboxPath getNewPath() { - return OTHER_MAILBOX_PATH; - } - }; - defaultDelegatingMailboxListener.event(event); - MailboxListener.MailboxEvent secondEvent = new MailboxListener.MailboxEvent(null, OTHER_MAILBOX_PATH, MAILBOX_ID) {}; - defaultDelegatingMailboxListener.event(secondEvent); - assertThat(mailboxEventCollector.getEvents()).containsOnly(event, secondEvent); - assertThat(eachNodeEventCollector.getEvents()).containsOnly(event, secondEvent); - assertThat(onceEventCollector.getEvents()).containsExactly(event, secondEvent); - } - - @Test - public void mailboxDeletionShouldUnregisterMAILBOXListeners() throws Exception { + public void mailboxDeletionShouldUnregisterMAILBOXListeners() { QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty()); QuotaCount deletedMessageCount = QuotaCount.count(123); QuotaSize totalDeletedSize = QuotaSize.size(456); @@ -145,7 +114,7 @@ public class DefaultDelegatingMailboxListenerTest { } @Test - public void mailboxDeletionShouldNotRegisterMAILBOXListenerToOtherPaths() throws Exception { + public void mailboxDeletionShouldNotRegisterMAILBOXListenerToOtherPaths() { QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty()); QuotaCount quotaCount = QuotaCount.count(123); QuotaSize quotaSize = QuotaSize.size(456); @@ -159,8 +128,8 @@ public class DefaultDelegatingMailboxListenerTest { } @Test - public void removeListenerShouldWork() throws Exception { - defaultDelegatingMailboxListener.removeListener(MAILBOX_PATH, mailboxEventCollector, null); + public void removeListenerShouldWork() { + defaultDelegatingMailboxListener.removeListener(MAILBOX_ID, mailboxEventCollector, null); MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {}; defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).isEmpty(); @@ -169,8 +138,8 @@ public class DefaultDelegatingMailboxListenerTest { } @Test - public void removeListenerShouldNotRemoveAListenerFromADifferentPath() throws Exception { - defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_PATH, mailboxEventCollector, null); + public void removeListenerShouldNotRemoveAListenerFromADifferentPath() { + defaultDelegatingMailboxListener.removeListener(OTHER_MAILBOX_ID, mailboxEventCollector, null); MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {}; defaultDelegatingMailboxListener.event(event); assertThat(mailboxEventCollector.getEvents()).containsExactly(event); @@ -179,7 +148,7 @@ public class DefaultDelegatingMailboxListenerTest { } @Test - public void removeGlobalListenerShouldWorkForONCE() throws Exception { + public void removeGlobalListenerShouldWorkForONCE() { defaultDelegatingMailboxListener.removeGlobalListener(eachNodeEventCollector, null); MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {}; defaultDelegatingMailboxListener.event(event); @@ -189,7 +158,7 @@ public class DefaultDelegatingMailboxListenerTest { } @Test - public void removeGlobalListenerShouldWorkForEACH_NODE() throws Exception { + public void removeGlobalListenerShouldWorkForEACH_NODE() { defaultDelegatingMailboxListener.removeGlobalListener(onceEventCollector, null); MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, MAILBOX_PATH, MAILBOX_ID) {}; defaultDelegatingMailboxListener.event(event); http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java ---------------------------------------------------------------------- diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java index 58b0e11..04d2b1a 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java @@ -23,15 +23,15 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import org.apache.james.mailbox.MailboxListener; -import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.MailboxId; +import org.apache.james.mailbox.model.TestId; import org.junit.Before; import org.junit.Test; - public class MailboxListenerRegistryTest { + private static final MailboxId MAILBOX_ID = TestId.of(42); + private static final MailboxId OTHER_MAILBOX_ID = TestId.of(43); - private static final MailboxPath MAILBOX_PATH = MailboxPath.forUser("user", "INBOX"); - private static final MailboxPath OTHER_MAILBOX_PATH = MailboxPath.forUser("user", "other"); private MailboxListenerRegistry testee; private MailboxListener mailboxListener; private MailboxListener otherMailboxListener; @@ -50,36 +50,36 @@ public class MailboxListenerRegistryTest { @Test public void getLocalMailboxListenersShouldReturnEmptyList() { - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty(); + assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty(); } @Test - public void addGlobalListenerShouldAddAGlobalListener() throws Exception { + public void addGlobalListenerShouldAddAGlobalListener() { testee.addGlobalListener(mailboxListener); assertThat(testee.getGlobalListeners()).containsOnly(mailboxListener); } @Test - public void addListenerShouldAddAListener() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxListener); + public void addListenerShouldAddAListener() { + testee.addListener(MAILBOX_ID, mailboxListener); - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsOnly(mailboxListener); + assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsOnly(mailboxListener); } @Test - public void addListenerTwiceShouldAddAListenerOnlyOnce() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxListener); - testee.addListener(MAILBOX_PATH, mailboxListener); + public void addListenerTwiceShouldAddAListenerOnlyOnce() { + testee.addListener(MAILBOX_ID, mailboxListener); + testee.addListener(MAILBOX_ID, mailboxListener); - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsExactly(mailboxListener); + assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsExactly(mailboxListener); } @Test - public void addListenerShouldAddAListenerOnCorrectPath() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxListener); + public void addListenerShouldAddAListenerOnCorrectPath() { + testee.addListener(MAILBOX_ID, mailboxListener); - assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).isEmpty(); + assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_ID)).isEmpty(); } @Test @@ -92,16 +92,16 @@ public class MailboxListenerRegistryTest { } @Test - public void removeListenerShouldWork() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxListener); + public void removeListenerShouldWork() { + testee.addListener(MAILBOX_ID, mailboxListener); - testee.removeListener(MAILBOX_PATH, mailboxListener); + testee.removeListener(MAILBOX_ID, mailboxListener); - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty(); + assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty(); } @Test - public void removeGlobalListenerShouldNotRemoveOtherListeners() throws Exception { + public void removeGlobalListenerShouldNotRemoveOtherListeners() { testee.addGlobalListener(mailboxListener); testee.addGlobalListener(otherMailboxListener); @@ -111,64 +111,32 @@ public class MailboxListenerRegistryTest { } @Test - public void removeListenerShouldNotRemoveOtherListeners() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxListener); - testee.addListener(MAILBOX_PATH, otherMailboxListener); - - testee.removeListener(MAILBOX_PATH, mailboxListener); - - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsOnly(otherMailboxListener); - } - - @Test - public void deleteRegistryForShouldRemoveAllListeners() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxListener); - testee.addListener(MAILBOX_PATH, otherMailboxListener); - - testee.deleteRegistryFor(MAILBOX_PATH); - - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty(); - } - - @Test - public void handleRenameShouldMoveListeners() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxListener); - testee.addListener(MAILBOX_PATH, otherMailboxListener); - - testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH); - - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty(); - assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener, otherMailboxListener); - } - - @Test - public void handleRenameShouldPreservePreviouslyRegisteredListeners() throws Exception { - testee.addListener(OTHER_MAILBOX_PATH, mailboxListener); + public void removeListenerShouldNotRemoveOtherListeners() { + testee.addListener(MAILBOX_ID, mailboxListener); + testee.addListener(MAILBOX_ID, otherMailboxListener); - testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH); + testee.removeListener(MAILBOX_ID, mailboxListener); - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty(); - assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener); + assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsOnly(otherMailboxListener); } @Test - public void handleRenameShouldMergeListenersIfNeeded() throws Exception { - testee.addListener(MAILBOX_PATH, mailboxListener); - testee.addListener(OTHER_MAILBOX_PATH, otherMailboxListener); + public void deleteRegistryForShouldRemoveAllListeners() { + testee.addListener(MAILBOX_ID, mailboxListener); + testee.addListener(MAILBOX_ID, otherMailboxListener); - testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH); + testee.deleteRegistryFor(MAILBOX_ID); - assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty(); - assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener, otherMailboxListener); + assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty(); } @Test - public void removeGlobalListenerShouldNotThrowOnAbsentListener() throws Exception { + public void removeGlobalListenerShouldNotThrowOnAbsentListener() { testee.removeGlobalListener(mailboxListener); } @Test - public void removeListenerShouldNotThrowOnAbsentListener() throws Exception { - testee.removeListener(MAILBOX_PATH, mailboxListener); + public void removeListenerShouldNotThrowOnAbsentListener() { + testee.removeListener(MAILBOX_ID, mailboxListener); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java index 01cab31..684c9e9 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java @@ -93,7 +93,7 @@ public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> impleme final IdleMailboxListener idleListener; if (sm != null) { idleListener = new IdleMailboxListener(session, responder); - mailboxManager.addListener(sm.getPath(), idleListener, mailboxSession); + mailboxManager.addListener(sm.getMailboxId(), idleListener, mailboxSession); } else { idleListener = null; } @@ -112,7 +112,7 @@ public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> impleme if (idleListener != null) { try { - mailboxManager.removeListener(sm.getPath(), idleListener, mailboxSession); + mailboxManager.removeListener(sm.getMailboxId(), idleListener, mailboxSession); } catch (MailboxException e) { LOGGER.error("Unable to remove idle listener for mailbox {}", sm.getPath(), e); } http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java index 9402ba1..f0eb68e 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java @@ -93,10 +93,11 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener { uidMsnConverter = new UidMsnConverter(); - mailboxManager.addListener(path, this, mailboxSession); - MessageManager messageManager = mailboxManager.getMailbox(path, mailboxSession); mailboxId = messageManager.getId(); + + mailboxManager.addListener(mailboxId, this, mailboxSession); + applicableFlags = messageManager.getApplicableFlags(mailboxSession); uidMsnConverter.addAll(ImmutableList.copyOf( messageManager.search(new SearchQuery(SearchQuery.all()), mailboxSession))); @@ -122,7 +123,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener { MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); try { - mailboxManager.removeListener(path, this, mailboxSession); + mailboxManager.removeListener(mailboxId, this, mailboxSession); } catch (MailboxException e) { LOGGER.error("Unable to remove listener {} from mailbox while closing it", this, e); } http://git-wip-us.apache.org/repos/asf/james-project/blob/d9bcebc7/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java ---------------------------------------------------------------------- diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java index b640cba..12daae0 100644 --- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java +++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java @@ -46,6 +46,7 @@ import org.apache.james.mailbox.model.MailboxConstants; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MessageMetaData; import org.apache.james.mailbox.model.SearchQuery; +import org.apache.james.mailbox.model.TestId; import org.apache.james.mailbox.store.SimpleMessageMetaData; import org.apache.james.mailbox.store.event.EventFactory; import org.apache.james.mailbox.store.mail.model.DefaultMessageId; @@ -74,6 +75,7 @@ public class SelectedMailboxImplTest { private MailboxPath mailboxPath; private ImapSession imapSession; private Mailbox mailbox; + private TestId mailboxId; @Before public void setUp() throws Exception { @@ -83,6 +85,7 @@ public class SelectedMailboxImplTest { messageManager = mock(MessageManager.class); imapSession = mock(ImapSession.class); mailbox = mock(Mailbox.class); + mailboxId = TestId.of(42); when(mailboxManager.getMailbox(eq(mailboxPath), any(MailboxSession.class))) .thenReturn(messageManager); @@ -90,6 +93,7 @@ public class SelectedMailboxImplTest { .thenReturn(new Flags()); when(messageManager.search(any(SearchQuery.class), any(MailboxSession.class))) .then(delayedSearchAnswer()); + when(messageManager.getId()).thenReturn(mailboxId); when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mock(MailboxSession.class)); @@ -107,7 +111,7 @@ public class SelectedMailboxImplTest { final AtomicInteger successCount = new AtomicInteger(0); doAnswer(generateEmitEventAnswer(successCount)) .when(mailboxManager) - .addListener(eq(mailboxPath), any(MailboxListener.class), any(MailboxSession.class)); + .addListener(eq(mailboxId), any(MailboxListener.class), any(MailboxSession.class)); SelectedMailboxImpl selectedMailbox = new SelectedMailboxImpl( mailboxManager, @@ -122,7 +126,7 @@ public class SelectedMailboxImplTest { final AtomicInteger successCount = new AtomicInteger(0); doAnswer(generateEmitEventAnswer(successCount)) .when(mailboxManager) - .addListener(eq(mailboxPath), any(MailboxListener.class), any(MailboxSession.class)); + .addListener(eq(mailboxId), any(MailboxListener.class), any(MailboxSession.class)); new SelectedMailboxImpl( mailboxManager, --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org