JAMES-2641 Remove MailboxListenerRegistry

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/90f18c4b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/90f18c4b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/90f18c4b

Branch: refs/heads/master
Commit: 90f18c4b9377cbe41cf76012bd2c9d7463f619a8
Parents: 89f168d
Author: Benoit Tellier <btell...@linagora.com>
Authored: Thu Jan 10 14:30:16 2019 +0700
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Thu Jan 17 10:23:41 2019 +0700

----------------------------------------------------------------------
 .../store/event/MailboxListenerRegistry.java    |  71 ----------
 .../event/MailboxListenerRegistryTest.java      | 142 -------------------
 .../modules/mailbox/DefaultEventModule.java     |   2 -
 .../modules/mailbox/MailboxListenerFactory.java |   6 +-
 .../modules/mailbox/MailboxListenersLoader.java |   5 +-
 .../mailbox/MailboxListenersLoaderImpl.java     |  19 ++-
 .../modules/mailbox/NoopMailboxListener.java    |   2 +-
 .../mailbox/MailboxListenersLoaderImplTest.java |  15 +-
 8 files changed, 22 insertions(+), 240 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/90f18c4b/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
deleted file mode 100644
index 83461e6..0000000
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxListenerRegistry.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mailbox.store.event;
-
-import java.util.List;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.model.MailboxId;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
-
-public class MailboxListenerRegistry {
-
-    private final Multimap<MailboxId, MailboxListener> listeners;
-    private final ConcurrentLinkedQueue<MailboxListener> globalListeners;
-
-    public MailboxListenerRegistry() {
-        this.globalListeners = new ConcurrentLinkedQueue<>();
-        this.listeners = Multimaps.synchronizedMultimap(HashMultimap.create());
-    }
-
-    public void addListener(MailboxId mailboxId, MailboxListener listener) {
-        listeners.put(mailboxId, listener);
-    }
-
-    public void addGlobalListener(MailboxListener listener) {
-        globalListeners.add(listener);
-    }
-
-    public void removeListener(MailboxId mailboxId, MailboxListener listener) {
-        listeners.remove(mailboxId, listener);
-    }
-
-    public void removeGlobalListener(MailboxListener listener) {
-        globalListeners.remove(listener);
-    }
-
-    public List<MailboxListener> getLocalMailboxListeners(MailboxId mailboxId) 
{
-        return ImmutableList.copyOf(listeners.get(mailboxId));
-    }
-
-    public List<MailboxListener> getGlobalListeners() {
-        return ImmutableList.copyOf(globalListeners);
-    }
-
-    public void deleteRegistryFor(MailboxId mailboxId) {
-        listeners.removeAll(mailboxId);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/90f18c4b/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
deleted file mode 100644
index 04d2b1a..0000000
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.mailbox.store.event;
-
-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.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 MailboxListenerRegistry testee;
-    private MailboxListener mailboxListener;
-    private MailboxListener otherMailboxListener;
-
-    @Before
-    public void setUp() {
-        testee = new MailboxListenerRegistry();
-        mailboxListener = mock(MailboxListener.class);
-        otherMailboxListener = mock(MailboxListener.class);
-    }
-
-    @Test
-    public void getGlobalListenersShouldBeEmpty() {
-        assertThat(testee.getGlobalListeners()).isEmpty();
-    }
-
-    @Test
-    public void getLocalMailboxListenersShouldReturnEmptyList() {
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty();
-    }
-
-    @Test
-    public void addGlobalListenerShouldAddAGlobalListener() {
-        testee.addGlobalListener(mailboxListener);
-
-        assertThat(testee.getGlobalListeners()).containsOnly(mailboxListener);
-    }
-
-    @Test
-    public void addListenerShouldAddAListener() {
-        testee.addListener(MAILBOX_ID, mailboxListener);
-
-        
assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsOnly(mailboxListener);
-    }
-
-    @Test
-    public void addListenerTwiceShouldAddAListenerOnlyOnce() {
-        testee.addListener(MAILBOX_ID, mailboxListener);
-        testee.addListener(MAILBOX_ID, mailboxListener);
-
-        
assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsExactly(mailboxListener);
-    }
-
-    @Test
-    public void addListenerShouldAddAListenerOnCorrectPath() {
-        testee.addListener(MAILBOX_ID, mailboxListener);
-
-        
assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_ID)).isEmpty();
-    }
-
-    @Test
-    public void removeGlobalListenerShouldWork() throws Exception {
-        testee.addGlobalListener(mailboxListener);
-
-        testee.removeGlobalListener(mailboxListener);
-
-        assertThat(testee.getGlobalListeners()).isEmpty();
-    }
-
-    @Test
-    public void removeListenerShouldWork() {
-        testee.addListener(MAILBOX_ID, mailboxListener);
-
-        testee.removeListener(MAILBOX_ID, mailboxListener);
-
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty();
-    }
-
-    @Test
-    public void removeGlobalListenerShouldNotRemoveOtherListeners() {
-        testee.addGlobalListener(mailboxListener);
-        testee.addGlobalListener(otherMailboxListener);
-
-        testee.removeGlobalListener(mailboxListener);
-
-        
assertThat(testee.getGlobalListeners()).containsOnly(otherMailboxListener);
-    }
-
-    @Test
-    public void removeListenerShouldNotRemoveOtherListeners() {
-        testee.addListener(MAILBOX_ID, mailboxListener);
-        testee.addListener(MAILBOX_ID, otherMailboxListener);
-
-        testee.removeListener(MAILBOX_ID, mailboxListener);
-
-        
assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).containsOnly(otherMailboxListener);
-    }
-
-    @Test
-    public void deleteRegistryForShouldRemoveAllListeners() {
-        testee.addListener(MAILBOX_ID, mailboxListener);
-        testee.addListener(MAILBOX_ID, otherMailboxListener);
-
-        testee.deleteRegistryFor(MAILBOX_ID);
-
-        assertThat(testee.getLocalMailboxListeners(MAILBOX_ID)).isEmpty();
-    }
-
-    @Test
-    public void removeGlobalListenerShouldNotThrowOnAbsentListener() {
-        testee.removeGlobalListener(mailboxListener);
-    }
-
-    @Test
-    public void removeListenerShouldNotThrowOnAbsentListener() {
-        testee.removeListener(MAILBOX_ID, mailboxListener);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/90f18c4b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
index 3ec0a61..79d2dab 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
@@ -31,7 +31,6 @@ import org.apache.james.mailbox.events.InVMEventBus;
 import org.apache.james.mailbox.events.delivery.EventDelivery;
 import org.apache.james.mailbox.events.delivery.InVmEventDelivery;
 import org.apache.james.mailbox.store.event.MailboxAnnotationListener;
-import org.apache.james.mailbox.store.event.MailboxListenerRegistry;
 import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
 import org.apache.james.server.core.configuration.ConfigurationProvider;
 import org.apache.james.utils.ConfigurationPerformer;
@@ -53,7 +52,6 @@ public class DefaultEventModule extends AbstractModule {
 
         bind(MailboxListenerFactory.class).in(Scopes.SINGLETON);
         bind(MailboxListenersLoaderImpl.class).in(Scopes.SINGLETON);
-        bind(MailboxListenerRegistry.class).in(Scopes.SINGLETON);
         
bind(MailboxListenersLoader.class).to(MailboxListenersLoaderImpl.class);
         Multibinder.newSetBinder(binder(), 
MailboxListener.GroupMailboxListener.class);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/90f18c4b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenerFactory.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenerFactory.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenerFactory.java
index 4c39661..9af26be 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenerFactory.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenerFactory.java
@@ -32,7 +32,7 @@ public class MailboxListenerFactory {
 
     public static class MailboxListenerBuilder {
         private final Injector injector;
-        private Optional<Class<MailboxListener>> clazz;
+        private Optional<Class<MailboxListener.GroupMailboxListener>> clazz;
         private Optional<MailboxListener.ExecutionMode> executionMode;
         private Optional<HierarchicalConfiguration> configuration;
 
@@ -63,12 +63,12 @@ public class MailboxListenerFactory {
             return this;
         }
 
-        public MailboxListenerBuilder clazz(Class<MailboxListener> clazz) {
+        public MailboxListenerBuilder 
clazz(Class<MailboxListener.GroupMailboxListener> clazz) {
             this.clazz = Optional.of(clazz);
             return this;
         }
 
-        public MailboxListener build() {
+        public MailboxListener.GroupMailboxListener build() {
             Preconditions.checkState(clazz.isPresent(), "'clazz' is 
mandatory");
             return injector.createChildInjector(
                 binder -> binder.bind(MailboxListener.ExecutionMode.class)

http://git-wip-us.apache.org/repos/asf/james-project/blob/90f18c4b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoader.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoader.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoader.java
index 46757a9..1909a3f 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoader.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoader.java
@@ -21,8 +21,7 @@ package org.apache.james.modules.mailbox;
 import org.apache.james.mailbox.MailboxListener;
 
 public interface MailboxListenersLoader {
+    MailboxListener.GroupMailboxListener createListener(ListenerConfiguration 
configuration);
 
-    MailboxListener createListener(ListenerConfiguration configuration);
-
-    void register(MailboxListener listener);
+    void register(MailboxListener.GroupMailboxListener listener);
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/90f18c4b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
index 44dc178..b4bf0fa 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImpl.java
@@ -23,7 +23,7 @@ import java.util.Set;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.store.event.MailboxListenerRegistry;
+import org.apache.james.mailbox.events.EventBus;
 import org.apache.james.utils.ExtendedClassLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,19 +31,18 @@ import org.slf4j.LoggerFactory;
 import com.google.inject.Inject;
 
 public class MailboxListenersLoaderImpl implements Configurable, 
MailboxListenersLoader {
-
     private static final Logger LOGGER = 
LoggerFactory.getLogger(MailboxListenersLoaderImpl.class);
 
     private final MailboxListenerFactory mailboxListenerFactory;
-    private final MailboxListenerRegistry registry;
+    private final EventBus eventBus;
     private final ExtendedClassLoader classLoader;
-    private final Set<MailboxListener> guiceDefinedListeners;
+    private final Set<MailboxListener.GroupMailboxListener> 
guiceDefinedListeners;
 
     @Inject
-    public MailboxListenersLoaderImpl(MailboxListenerFactory 
mailboxListenerFactory, MailboxListenerRegistry registry,
-                                  ExtendedClassLoader classLoader, 
Set<MailboxListener> guiceDefinedListeners) {
+    public MailboxListenersLoaderImpl(MailboxListenerFactory 
mailboxListenerFactory, EventBus eventBus,
+                                  ExtendedClassLoader classLoader, 
Set<MailboxListener.GroupMailboxListener> guiceDefinedListeners) {
         this.mailboxListenerFactory = mailboxListenerFactory;
-        this.registry = registry;
+        this.eventBus = eventBus;
         this.classLoader = classLoader;
         this.guiceDefinedListeners = guiceDefinedListeners;
     }
@@ -62,12 +61,12 @@ public class MailboxListenersLoaderImpl implements 
Configurable, MailboxListener
     }
 
     @Override
-    public void register(MailboxListener listener) {
-        registry.addGlobalListener(listener);
+    public void register(MailboxListener.GroupMailboxListener listener) {
+        eventBus.register(listener);
     }
 
     @Override
-    public MailboxListener createListener(ListenerConfiguration configuration) 
{
+    public MailboxListener.GroupMailboxListener 
createListener(ListenerConfiguration configuration) {
         String listenerClass = configuration.getClazz();
         try {
             LOGGER.info("Loading user registered mailbox listener {}", 
listenerClass);

http://git-wip-us.apache.org/repos/asf/james-project/blob/90f18c4b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/NoopMailboxListener.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/NoopMailboxListener.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/NoopMailboxListener.java
index f5c10d5..1c1f555 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/NoopMailboxListener.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/NoopMailboxListener.java
@@ -25,7 +25,7 @@ import org.apache.james.mailbox.events.Group;
 public class NoopMailboxListener implements 
MailboxListener.GroupMailboxListener {
     private static class NoopMailboxListenerGroup extends Group {}
 
-    public static final Group GROUP = new NoopMailboxListenerGroup();
+    static final Group GROUP = new NoopMailboxListenerGroup();
 
     @Override
     public ListenerType getType() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/90f18c4b/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java
 
b/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java
index c1d6f5f..a9f454d 100644
--- 
a/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java
+++ 
b/server/container/guice/mailbox/src/test/java/org/apache/james/modules/mailbox/MailboxListenersLoaderImplTest.java
@@ -32,7 +32,9 @@ import 
org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.store.event.MailboxListenerRegistry;
+import org.apache.james.mailbox.events.InVMEventBus;
+import org.apache.james.mailbox.events.delivery.InVmEventDelivery;
+import org.apache.james.metrics.api.NoopMetricFactory;
 import org.apache.james.utils.ExtendedClassLoader;
 import org.junit.Before;
 import org.junit.Test;
@@ -42,7 +44,7 @@ import com.google.inject.Guice;
 
 public class MailboxListenersLoaderImplTest {
 
-    private MailboxListenerRegistry registry;
+    private InVMEventBus eventBus;
     private MailboxListenersLoaderImpl testee;
 
     @Before
@@ -51,8 +53,8 @@ public class MailboxListenersLoaderImplTest {
         when(fileSystem.getFile(anyString()))
             .thenThrow(new FileNotFoundException());
 
-        registry = new MailboxListenerRegistry();
-        testee = new MailboxListenersLoaderImpl(new 
MailboxListenerFactory(Guice.createInjector()), registry,
+        eventBus = new InVMEventBus(new InVmEventDelivery(new 
NoopMetricFactory()));
+        testee = new MailboxListenersLoaderImpl(new 
MailboxListenerFactory(Guice.createInjector()), eventBus,
             new ExtendedClassLoader(fileSystem), ImmutableSet.of());
     }
 
@@ -95,14 +97,11 @@ public class MailboxListenersLoaderImplTest {
                     "<listener>" +
                         
"<class>org.apache.james.modules.mailbox.NoopMailboxListener</class>" +
                     "</listener>" +
-                    "<listener>" +
-                        
"<class>org.apache.james.modules.mailbox.NoopMailboxListener</class>" +
-                    "</listener>" +
                 "</listeners>");
 
         testee.configure(configuration);
 
-        assertThat(registry.getGlobalListeners()).hasSize(2);
+        
assertThat(eventBus.registeredGroups()).containsExactly(NoopMailboxListener.GROUP);
     }
 
     private DefaultConfigurationBuilder toConfigutation(String 
configurationString) throws ConfigurationException {


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

Reply via email to