james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [10/15] james-project git commit: JAMES-2368 Wrap guice injector in a factory class for MailboxListener
Date Fri, 04 May 2018 06:54:16 GMT
JAMES-2368 Wrap guice injector in a factory class for MailboxListener


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

Branch: refs/heads/master
Commit: e4408581f047f6f6a9120a1bcbd3468195f53476
Parents: a87f701
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Thu May 3 14:43:27 2018 +0200
Committer: benwa <btellier@linagora.com>
Committed: Fri May 4 13:39:07 2018 +0700

----------------------------------------------------------------------
 .../modules/mailbox/DefaultEventModule.java     |  1 +
 .../modules/mailbox/MailboxListenerFactory.java | 39 ++++++++++++++++++++
 .../mailbox/MailboxListenersLoaderImpl.java     |  9 ++---
 .../mailbox/MailboxListenersLoaderImplTest.java |  2 +-
 4 files changed, 45 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e4408581/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 67a63b7..e5ee1b3 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
@@ -58,6 +58,7 @@ public class DefaultEventModule extends AbstractModule {
         bind(ListeningCurrentQuotaUpdater.class).in(Scopes.SINGLETON);
         bind(MailboxAnnotationListener.class).in(Scopes.SINGLETON);
 
+        bind(MailboxListenerFactory.class).in(Scopes.SINGLETON);
         bind(MailboxListenersLoaderImpl.class).in(Scopes.SINGLETON);
         bind(MailboxListenerRegistry.class).in(Scopes.SINGLETON);
         bind(MailboxListenersLoader.class).to(MailboxListenersLoaderImpl.class);

http://git-wip-us.apache.org/repos/asf/james-project/blob/e4408581/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
new file mode 100644
index 0000000..500517b
--- /dev/null
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/MailboxListenerFactory.java
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.modules.mailbox;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.MailboxListener;
+
+import com.google.inject.Injector;
+
+public class MailboxListenerFactory {
+
+    private final Injector injector;
+
+    @Inject
+    public MailboxListenerFactory(Injector injector) {
+        this.injector = injector;
+    }
+
+    public MailboxListener createInstance(Class<MailboxListener> clazz) {
+        return injector.getInstance(clazz);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e4408581/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 16b7608..d8476be 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
@@ -30,21 +30,20 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.inject.Inject;
-import com.google.inject.Injector;
 
 public class MailboxListenersLoaderImpl implements Configurable, MailboxListenersLoader {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(MailboxListenersLoaderImpl.class);
 
-    private final Injector injector;
+    private final MailboxListenerFactory mailboxListenerFactory;
     private final MailboxListenerRegistry registry;
     private final ExtendedClassLoader classLoader;
     private final Set<MailboxListener> guiceDefinedListeners;
 
     @Inject
-    public MailboxListenersLoaderImpl(Injector injector, MailboxListenerRegistry registry,
+    public MailboxListenersLoaderImpl(MailboxListenerFactory mailboxListenerFactory, MailboxListenerRegistry
registry,
                                   ExtendedClassLoader classLoader, Set<MailboxListener>
guiceDefinedListeners) {
-        this.injector = injector;
+        this.mailboxListenerFactory = mailboxListenerFactory;
         this.registry = registry;
         this.classLoader = classLoader;
         this.guiceDefinedListeners = guiceDefinedListeners;
@@ -78,7 +77,7 @@ public class MailboxListenersLoaderImpl implements Configurable, MailboxListener
         try {
             LOGGER.info("Loading user registered mailbox listener {}", listenerClass);
             Class<MailboxListener> clazz = classLoader.locateClass(listenerClass);
-            MailboxListener listener = injector.getInstance(clazz);
+            MailboxListener listener = mailboxListenerFactory.createInstance(clazz);
             return listener;
         } catch (ClassNotFoundException e) {
             LOGGER.error("Error while loading user registered global listener {}", listenerClass,
e);

http://git-wip-us.apache.org/repos/asf/james-project/blob/e4408581/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 d243db4..aeff77d 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
@@ -52,7 +52,7 @@ public class MailboxListenersLoaderImplTest {
             .thenThrow(new FileNotFoundException());
 
         registry = new MailboxListenerRegistry();
-        testee = new MailboxListenersLoaderImpl(Guice.createInjector(), registry,
+        testee = new MailboxListenersLoaderImpl(new MailboxListenerFactory(Guice.createInjector()),
registry,
             new ExtendedClassLoader(fileSystem), ImmutableSet.of());
     }
 


---------------------------------------------------------------------
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