james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [02/15] james-project git commit: JAMES-2368 Register global custom listeners in guice
Date Fri, 04 May 2018 06:54:08 GMT
JAMES-2368 Register global custom listeners in guice


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

Branch: refs/heads/master
Commit: 4891e3118e7473b47ef7cedfaf87bb9e5bf581ca
Parents: a1cdcf5
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Mon Apr 30 16:36:02 2018 +0200
Committer: benwa <btellier@linagora.com>
Committed: Fri May 4 13:38:02 2018 +0700

----------------------------------------------------------------------
 .../store/event/MailboxAnnotationListener.java  |  3 ++
 .../modules/mailbox/CassandraMailboxModule.java |  5 ---
 .../src/test/resources/listeners.xml            | 31 +++++++++++++++++
 .../SpamAssassinListenerModule.java             |  4 ---
 .../modules/mailbox/DefaultEventModule.java     | 35 +++++++++-----------
 .../src/test/resources/listeners.xml            | 28 ++++++++++++++++
 .../java/org/apache/james/jmap/JMAPModule.java  |  4 ---
 7 files changed, 78 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4891e311/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
index 4ac362e..379f225 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/MailboxAnnotationListener.java
@@ -20,6 +20,8 @@ package org.apache.james.mailbox.store.event;
 
 import java.util.List;
 
+import javax.inject.Inject;
+
 import org.apache.james.mailbox.Event;
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -34,6 +36,7 @@ public class MailboxAnnotationListener implements MailboxListener {
     private static final Logger logger = LoggerFactory.getLogger(MailboxAnnotationListener.class);
     private MailboxSessionMapperFactory mailboxSessionMapperFactory;
 
+    @Inject
     public MailboxAnnotationListener(MailboxSessionMapperFactory mailboxSessionMapperFactory)
{
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4891e311/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
index f6a4ea5..69a44fc 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java
@@ -25,7 +25,6 @@ import org.apache.james.adapter.mailbox.store.UserRepositoryAuthorizator;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.mailbox.AttachmentManager;
 import org.apache.james.mailbox.BlobManager;
-import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxPathLocker;
 import org.apache.james.mailbox.MessageIdManager;
@@ -34,7 +33,6 @@ import org.apache.james.mailbox.SubscriptionManager;
 import org.apache.james.mailbox.cassandra.CassandraMailboxManager;
 import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory;
 import org.apache.james.mailbox.cassandra.CassandraSubscriptionManager;
-import org.apache.james.mailbox.cassandra.MailboxOperationLoggingListener;
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
 import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
 import org.apache.james.mailbox.cassandra.mail.CassandraACLMapper;
@@ -152,9 +150,6 @@ public class CassandraMailboxModule extends AbstractModule {
         bind(AttachmentManager.class).to(StoreAttachmentManager.class);
         bind(RightManager.class).to(StoreRightManager.class);
 
-        Multibinder<MailboxListener> mailboxListeners = Multibinder.newSetBinder(binder(),
MailboxListener.class);
-        mailboxListeners.addBinding().to(MailboxOperationLoggingListener.class);
-
         Multibinder<CassandraModule> cassandraDataDefinitions = Multibinder.newSetBinder(binder(),
CassandraModule.class);
         cassandraDataDefinitions.addBinding().to(org.apache.james.mailbox.cassandra.modules.CassandraAclModule.class);
         cassandraDataDefinitions.addBinding().to(org.apache.james.mailbox.cassandra.modules.CassandraAnnotationModule.class);

http://git-wip-us.apache.org/repos/asf/james-project/blob/4891e311/server/container/guice/cassandra-guice/src/test/resources/listeners.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/resources/listeners.xml b/server/container/guice/cassandra-guice/src/test/resources/listeners.xml
new file mode 100644
index 0000000..35ca919
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/resources/listeners.xml
@@ -0,0 +1,31 @@
+<?xml version="1.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.                                           
+ -->
+
+<listeners>
+  <listener>
+    <class>org.apache.james.jmap.event.PropagateLookupRightListener</class>
+  </listener>
+  <listener>
+    <class>org.apache.james.mailbox.spamassassin.SpamAssassinListener</class>
+  </listener>
+  <listener>
+    <class>org.apache.james.mailbox.cassandra.MailboxOperationLoggingListener</class>
+  </listener>
+</listeners>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/4891e311/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
b/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
index 8f0550f..9a96618 100644
--- a/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
+++ b/server/container/guice/mailbox-plugin-spamassassin/src/main/java/org/apache/james/modules/spamassassin/SpamAssassinListenerModule.java
@@ -25,7 +25,6 @@ import javax.inject.Singleton;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.spamassassin.SpamAssassinConfiguration;
 import org.apache.james.mailbox.spamassassin.SpamAssassinListener;
 import org.apache.james.utils.PropertiesProvider;
@@ -35,7 +34,6 @@ import org.slf4j.LoggerFactory;
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
 import com.google.inject.Scopes;
-import com.google.inject.multibindings.Multibinder;
 
 public class SpamAssassinListenerModule extends AbstractModule {
     private static final Logger LOGGER = LoggerFactory.getLogger(SpamAssassinListenerModule.class);
@@ -45,8 +43,6 @@ public class SpamAssassinListenerModule extends AbstractModule {
     @Override
     protected void configure() {
         bind(SpamAssassinListener.class).in(Scopes.SINGLETON);
-
-        Multibinder.newSetBinder(binder(), MailboxListener.class).addBinding().to(SpamAssassinListener.class);
     }
 
     @Provides

http://git-wip-us.apache.org/repos/asf/james-project/blob/4891e311/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 e515a1f..96e695c 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
@@ -20,27 +20,23 @@
 package org.apache.james.modules.mailbox;
 
 import java.util.List;
-import java.util.Set;
 
-import javax.inject.Named;
+import javax.inject.Inject;
 
+import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.lifecycle.api.Configurable;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.EventDelivery;
+import org.apache.james.mailbox.store.event.MailboxAnnotationListener;
 import org.apache.james.mailbox.store.event.SynchronousEventDelivery;
-import org.apache.james.modules.Names;
+import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
 import org.apache.james.utils.ConfigurationPerformer;
+import org.apache.james.utils.ConfigurationProvider;
 
-import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
-import com.google.inject.Inject;
 import com.google.inject.Scopes;
 import com.google.inject.Singleton;
 import com.google.inject.multibindings.Multibinder;
@@ -56,28 +52,29 @@ public class DefaultEventModule extends AbstractModule {
         bind(EventDelivery.class).to(SynchronousEventDelivery.class);
 
         Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(ListenerRegistrationPerformer.class);
-        Multibinder.newSetBinder(binder(), MailboxListener.class);
+
+        bind(ListeningCurrentQuotaUpdater.class).in(Scopes.SINGLETON);
+        bind(MailboxAnnotationListener.class).in(Scopes.SINGLETON);
+
+        bind(GlobalMailboxListeners.class).in(Scopes.SINGLETON);
     }
 
     @Singleton
     public static class ListenerRegistrationPerformer implements ConfigurationPerformer {
-        private final MailboxManager mailboxManager;
-        private final Set<MailboxListener> listeners;
+        private final ConfigurationProvider configurationProvider;
+        private final GlobalMailboxListeners listeners;
 
         @Inject
-        public ListenerRegistrationPerformer(@Named(Names.MAILBOXMANAGER_NAME) MailboxManager
mailboxManager,
-                                             Set<MailboxListener> listeners) {
-            this.mailboxManager = mailboxManager;
+        public ListenerRegistrationPerformer(ConfigurationProvider configurationProvider,
GlobalMailboxListeners listeners) {
+            this.configurationProvider = configurationProvider;
             this.listeners = listeners;
         }
 
         @Override
         public void initModule() {
             try {
-                MailboxSession systemSession = mailboxManager.createSystemSession("storeMailboxManager");
-                listeners.forEach(Throwing.consumer(listener ->
-                    mailboxManager.addGlobalListener(listener, systemSession)));
-            } catch (MailboxException e) {
+                listeners.configure(configurationProvider.getConfiguration("listeners"));
+            } catch (ConfigurationException e) {
                 Throwables.propagate(e);
             }
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4891e311/server/container/guice/memory-guice/src/test/resources/listeners.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/test/resources/listeners.xml b/server/container/guice/memory-guice/src/test/resources/listeners.xml
new file mode 100644
index 0000000..70b32e1
--- /dev/null
+++ b/server/container/guice/memory-guice/src/test/resources/listeners.xml
@@ -0,0 +1,28 @@
+<?xml version="1.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.                                           
+ -->
+
+<listeners>
+  <listener>
+    <class>org.apache.james.jmap.event.PropagateLookupRightListener</class>
+  </listener>
+  <listener>
+    <class>org.apache.james.mailbox.spamassassin.SpamAssassinListener</class>
+  </listener>
+</listeners>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/4891e311/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
index b5bd236..97e5834 100644
--- a/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
+++ b/server/container/guice/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPModule.java
@@ -29,7 +29,6 @@ import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.commons.io.FileUtils;
 import org.apache.james.filesystem.api.FileSystem;
-import org.apache.james.jmap.event.PropagateLookupRightListener;
 import org.apache.james.jmap.mailet.VacationMailet;
 import org.apache.james.jmap.methods.RequestHandler;
 import org.apache.james.jmap.send.PostDequeueDecoratorFactory;
@@ -39,7 +38,6 @@ import org.apache.james.jmap.utils.SystemMailboxesProvider;
 import org.apache.james.jmap.utils.SystemMailboxesProviderImpl;
 import org.apache.james.jwt.JwtConfiguration;
 import org.apache.james.lifecycle.api.Configurable;
-import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxManager.SearchCapabilities;
 import org.apache.james.mailetcontainer.impl.MatcherMailetPair;
@@ -97,8 +95,6 @@ public class JMAPModule extends AbstractModule {
         
         bind(SystemMailboxesProvider.class).to(SystemMailboxesProviderImpl.class);
         bind(MailQueueItemDecoratorFactory.class).to(PostDequeueDecoratorFactory.class).in(Scopes.SINGLETON);
-
-        Multibinder.newSetBinder(binder(), MailboxListener.class).addBinding().to(PropagateLookupRightListener.class);
     }
 
     @Provides


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


Mime
View raw message