This is an automated email from the ASF dual-hosted git repository.

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

commit 73ea004fcc7eeea3cd93bf39d5e87359e17a9b69
Author: Benoit Tellier <[email protected]>
AuthorDate: Wed Nov 18 12:57:14 2020 +0700

    JAMES-3441 Avoid starting mail spooler when 'threads' = 0
    
    This allows configuring which James instances, within a distributed 
topology, should
    handle mail processing.
---
 .../james/mailetcontainer/impl/JamesMailSpooler.java  | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailSpooler.java
 
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailSpooler.java
index 23623db..6244e4c 100644
--- 
a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailSpooler.java
+++ 
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/JamesMailSpooler.java
@@ -53,6 +53,8 @@ import org.apache.mailet.Mail;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
+
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 import reactor.core.scheduler.Schedulers;
@@ -227,12 +229,17 @@ public class JamesMailSpooler implements Disposable, 
Configurable, MailSpoolerMB
      */
     @PostConstruct
     public void init() {
-        LOGGER.info("init...");
-        LOGGER.info("Concurrency level is {}", concurrencyLevel);
-        MailQueue queue = queueFactory.createQueue(MailQueueFactory.SPOOL, 
MailQueueFactory.prefetchCount(concurrencyLevel));
-        runner = Optional.of(new Runner(metricFactory,
-            mailProcessor, errorRepository(), errorRepositoryURL, queue, 
concurrencyLevel));
-        LOGGER.info("Spooler started");
+        Preconditions.checkArgument(concurrencyLevel >= 0, "'threads' needs to 
be greater than or equal to zero");
+        if (concurrencyLevel > 0) {
+            LOGGER.info("init...");
+            LOGGER.info("Concurrency level is {}", concurrencyLevel);
+            MailQueue queue = queueFactory.createQueue(MailQueueFactory.SPOOL, 
MailQueueFactory.prefetchCount(concurrencyLevel));
+            runner = Optional.of(new Runner(metricFactory,
+                mailProcessor, errorRepository(), errorRepositoryURL, queue, 
concurrencyLevel));
+            LOGGER.info("Spooler started");
+        } else {
+            LOGGER.info("Spooler had been dis-activated. To enable is set 
'threads' count to a value greater than zero");
+        }
     }
 
     private MailRepository errorRepository() {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to