james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [james-project] branch master updated: JAMES-1902 Avoid creating the SPOOL MailQueue upon injection
Date Fri, 14 Jun 2019 14:30:10 GMT
This is an automated email from the ASF dual-hosted git repository.

rouazana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 8b9198c  JAMES-1902 Avoid creating the SPOOL MailQueue upon injection
     new db793aa  Merge remote-tracking branch 'benoit/mailetContext'
8b9198c is described below

commit 8b9198c3fa0624df61a24416ada24b5584496159
Author: Benoit Tellier <btellier@linagora.com>
AuthorDate: Thu Jun 13 13:46:25 2019 +0700

    JAMES-1902 Avoid creating the SPOOL MailQueue upon injection
    
    Reusing a maybe not yet initialized component is dangerous. We should
    rather do this as a startable to ensure initialization is well performed
    
    Additionally, JamesMailetContext should rely of constructor based injected
    final fields where possible.
---
 .../modules/server/CamelMailetContainerModule.java | 20 +---------------
 .../mailetcontainer/impl/JamesMailetContext.java   | 27 ++++++----------------
 .../impl/JamesMailetContextTest.java               |  8 +++----
 3 files changed, 12 insertions(+), 43 deletions(-)

diff --git a/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
b/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
index 8071593..3d0aa24 100644
--- a/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
+++ b/server/container/guice/mailet/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java
@@ -28,8 +28,6 @@ import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.SimpleRegistry;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.james.dnsservice.api.DNSService;
-import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.lifecycle.api.Startable;
 import org.apache.james.mailetcontainer.api.MailProcessor;
 import org.apache.james.mailetcontainer.api.MailetLoader;
@@ -44,7 +42,6 @@ import org.apache.james.queue.api.MailQueueFactory;
 import org.apache.james.server.core.configuration.ConfigurationProvider;
 import org.apache.james.transport.mailets.RemoveMimeHeader;
 import org.apache.james.transport.matchers.All;
-import org.apache.james.user.api.UsersRepository;
 import org.apache.james.utils.ConfigurationPerformer;
 import org.apache.james.utils.GuiceMailetLoader;
 import org.apache.james.utils.GuiceMatcherLoader;
@@ -61,7 +58,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
-import com.google.inject.Provides;
 import com.google.inject.Scopes;
 import com.google.inject.Singleton;
 import com.google.inject.multibindings.Multibinder;
@@ -84,6 +80,7 @@ public class CamelMailetContainerModule extends AbstractModule {
         bind(JamesMailSpooler.class).in(Scopes.SINGLETON);
         bind(MailSpoolerMBean.class).to(JamesMailSpooler.class);
 
+        bind(JamesMailetContext.class).in(Scopes.SINGLETON);
         bind(MailetContext.class).to(JamesMailetContext.class);
 
         bind(MailetLoader.class).to(GuiceMailetLoader.class);
@@ -97,20 +94,6 @@ public class CamelMailetContainerModule extends AbstractModule {
         transportProcessorChecks.addBinding().toInstance(BCC_Check);
     }
 
-    @Provides
-    @Singleton
-    private JamesMailetContext provideMailetContext(MailQueueFactory<?> mailQueueFactory,
-                                                    DNSService dns,
-                                                    UsersRepository localusers,
-                                                    DomainList domains) {
-        JamesMailetContext jamesMailetContext = new JamesMailetContext();
-        jamesMailetContext.setDNSService(dns);
-        jamesMailetContext.retrieveRootMailQueue(mailQueueFactory);
-        jamesMailetContext.setUsersRepository(localusers);
-        jamesMailetContext.setDomainList(domains);
-        return jamesMailetContext;
-    }
-
     @Singleton
     public static class MailetModuleConfigurationPerformer implements ConfigurationPerformer
{
 
@@ -189,7 +172,6 @@ public class CamelMailetContainerModule extends AbstractModule {
 
         private void configureMailetContext() throws ConfigurationException {
             mailetContext.configure(getMailetContextConfiguration());
-            mailetContext.retrieveRootMailQueue(mailQueueFactory);
         }
 
         private HierarchicalConfiguration getMailetContextConfiguration() {
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
index de97f11..ea8a0bf 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailetContext.java
@@ -72,34 +72,20 @@ public class JamesMailetContext implements MailetContext, Configurable
{
      * A hash table of server attributes These are the MailetContext attributes
      */
     private final Map<String, Object> attributes = new ConcurrentHashMap<>();
-    protected DNSService dns;
-
-    private UsersRepository localusers;
 
+    protected final DNSService dns;
+    private final UsersRepository localusers;
+    private final DomainList domains;
+    private final MailQueueFactory<?> mailQueueFactory;
     private MailQueue rootMailQueue;
-
-    private DomainList domains;
-
     private MailAddress postmaster;
 
     @Inject
-    public void retrieveRootMailQueue(MailQueueFactory<?> mailQueueFactory) {
-        this.rootMailQueue = mailQueueFactory.createQueue(MailQueueFactory.SPOOL);
-    }
-
-    @Inject
-    public void setDNSService(DNSService dns) {
+    public JamesMailetContext(DNSService dns, UsersRepository localusers, DomainList domains,
MailQueueFactory<?> mailQueueFactory) {
         this.dns = dns;
-    }
-
-    @Inject
-    public void setUsersRepository(UsersRepository localusers) {
         this.localusers = localusers;
-    }
-
-    @Inject
-    public void setDomainList(DomainList domains) {
         this.domains = domains;
+        this.mailQueueFactory = mailQueueFactory;
     }
 
     @Override
@@ -460,6 +446,7 @@ public class JamesMailetContext implements MailetContext, Configurable
{
 
     @Override
     public void configure(HierarchicalConfiguration config) throws ConfigurationException
{
+        this.rootMailQueue = mailQueueFactory.createQueue(MailQueueFactory.SPOOL);
         try {
 
             // Get postmaster
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
index 09c85c5..c08ee1f 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
 
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.james.core.Domain;
 import org.apache.james.core.MailAddress;
 import org.apache.james.core.builder.MimeMessageBuilder;
@@ -79,13 +80,12 @@ public class JamesMailetContextTest {
 
         usersRepository = MemoryUsersRepository.withVirtualHosting();
         usersRepository.setDomainList(domainList);
-        testee = new JamesMailetContext();
         MailQueueFactory<MailQueue> mailQueueFactory = mock(MailQueueFactory.class);
         spoolMailQueue = mock(MailQueue.class);
         when(mailQueueFactory.createQueue(MailQueueFactory.SPOOL)).thenReturn(spoolMailQueue);
-        testee.retrieveRootMailQueue(mailQueueFactory);
-        testee.setDomainList(domainList);
-        testee.setUsersRepository(usersRepository);
+        DNSService dnsService = null;
+        testee = new JamesMailetContext(dnsService, usersRepository, domainList, mailQueueFactory);
+        testee.configure(new HierarchicalConfiguration());
         mailAddress = new MailAddress(USERMAIL);
     }
 


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