james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/8] james-project git commit: JAMES-2544 RabbitMQMailQueue.Factory and RabbitMQMailQueueFactory is the same thing
Date Wed, 03 Oct 2018 09:45:08 GMT
JAMES-2544 RabbitMQMailQueue.Factory and RabbitMQMailQueueFactory is the same thing

	Move Inner Factory class to RabbitMQMailQueueFactory


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

Branch: refs/heads/master
Commit: 4889416c6f62e7806449b8a0e3420d44f3299bc9
Parents: 9e68612
Author: Matthieu Baechler <matthieu@apache.org>
Authored: Fri Sep 28 15:14:30 2018 +0200
Committer: duc <dtran@linagora.com>
Committed: Wed Oct 3 12:06:02 2018 +0700

----------------------------------------------------------------------
 .../james/queue/rabbitmq/RabbitMQMailQueue.java | 42 -------------
 .../rabbitmq/RabbitMQMailQueueFactory.java      | 63 ++++++++++++++++++--
 .../queue/rabbitmq/RabbitMQMailQueueTest.java   |  2 +-
 .../rabbitmq/RabbitMqMailQueueFactoryTest.java  |  2 +-
 4 files changed, 61 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4889416c/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
index fe6487a..1832dc2 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
@@ -45,48 +45,6 @@ public class RabbitMQMailQueue implements ManageableMailQueue {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQMailQueue.class);
 
-    static class Factory {
-        private final MetricFactory metricFactory;
-        private final GaugeRegistry gaugeRegistry;
-        private final RabbitClient rabbitClient;
-        private final Store<MimeMessage, MimeMessagePartsId> mimeMessageStore;
-        private final MailReferenceSerializer mailReferenceSerializer;
-        private final Function<MailReferenceDTO, Mail> mailLoader;
-        private final MailQueueView mailQueueView;
-        private final Clock clock;
-
-        @Inject
-        @VisibleForTesting Factory(MetricFactory metricFactory, GaugeRegistry gaugeRegistry,
-                                   RabbitClient rabbitClient,
-                                   Store<MimeMessage, MimeMessagePartsId> mimeMessageStore,
-                                   BlobId.Factory blobIdFactory,
-                                   MailQueueView mailQueueView,
-                                   Clock clock) {
-            this.metricFactory = metricFactory;
-            this.gaugeRegistry = gaugeRegistry;
-            this.rabbitClient = rabbitClient;
-            this.mimeMessageStore = mimeMessageStore;
-            this.mailQueueView = mailQueueView;
-            this.clock = clock;
-            this.mailReferenceSerializer = new MailReferenceSerializer();
-            this.mailLoader = Throwing.function(new MailLoader(mimeMessageStore, blobIdFactory)::load).sneakyThrow();
-        }
-
-        RabbitMQMailQueue create(MailQueueName mailQueueName) {
-            mailQueueView.initialize(mailQueueName);
-
-            return new RabbitMQMailQueue(
-                metricFactory,
-                mailQueueName,
-                gaugeRegistry,
-                new Enqueuer(mailQueueName, rabbitClient, mimeMessageStore, mailReferenceSerializer,
-                    metricFactory, mailQueueView, clock),
-                new Dequeuer(mailQueueName, rabbitClient, mailLoader, mailReferenceSerializer,
-                    metricFactory, mailQueueView),
-                mailQueueView);
-        }
-    }
-
     private final MailQueueName name;
     private final MetricFactory metricFactory;
     private final GaugeRegistry gaugeRegistry;

http://git-wip-us.apache.org/repos/asf/james-project/blob/4889416c/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java
index cec1306..1914335 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueFactory.java
@@ -19,21 +19,76 @@
 
 package org.apache.james.queue.rabbitmq;
 
+import java.time.Clock;
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
 
 import javax.inject.Inject;
+import javax.mail.internet.MimeMessage;
 
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.Store;
+import org.apache.james.blob.mail.MimeMessagePartsId;
+import org.apache.james.metrics.api.GaugeRegistry;
+import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.queue.api.MailQueueFactory;
+import org.apache.james.queue.rabbitmq.view.api.MailQueueView;
+import org.apache.mailet.Mail;
 
+import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableSet;
 
 public class RabbitMQMailQueueFactory implements MailQueueFactory<RabbitMQMailQueue>
{
+
+    @VisibleForTesting static class PrivateFactory {
+        private final MetricFactory metricFactory;
+        private final GaugeRegistry gaugeRegistry;
+        private final RabbitClient rabbitClient;
+        private final Store<MimeMessage, MimeMessagePartsId> mimeMessageStore;
+        private final MailReferenceSerializer mailReferenceSerializer;
+        private final Function<MailReferenceDTO, Mail> mailLoader;
+        private final MailQueueView mailQueueView;
+        private final Clock clock;
+
+        @Inject
+        @VisibleForTesting PrivateFactory(MetricFactory metricFactory,
+                                          GaugeRegistry gaugeRegistry,
+                                          RabbitClient rabbitClient,
+                                          Store<MimeMessage, MimeMessagePartsId> mimeMessageStore,
+                                          BlobId.Factory blobIdFactory,
+                                          MailQueueView mailQueueView,
+                                          Clock clock) {
+            this.metricFactory = metricFactory;
+            this.gaugeRegistry = gaugeRegistry;
+            this.rabbitClient = rabbitClient;
+            this.mimeMessageStore = mimeMessageStore;
+            this.mailQueueView = mailQueueView;
+            this.clock = clock;
+            this.mailReferenceSerializer = new MailReferenceSerializer();
+            this.mailLoader = Throwing.function(new MailLoader(mimeMessageStore, blobIdFactory)::load).sneakyThrow();
+        }
+
+        RabbitMQMailQueue create(MailQueueName mailQueueName) {
+            mailQueueView.initialize(mailQueueName);
+
+            return new RabbitMQMailQueue(
+                metricFactory,
+                mailQueueName,
+                gaugeRegistry,
+                new Enqueuer(mailQueueName, rabbitClient, mimeMessageStore, mailReferenceSerializer,
+                    metricFactory, mailQueueView, clock),
+                new Dequeuer(mailQueueName, rabbitClient, mailLoader, mailReferenceSerializer,
+                    metricFactory, mailQueueView),
+                mailQueueView);
+        }
+    }
+
     private final RabbitClient rabbitClient;
     private final RabbitMQManagementApi mqManagementApi;
-    private final RabbitMQMailQueue.Factory mailQueueFactory;
+    private final PrivateFactory privateFactory;
 
     // We store created queues to avoid duplicating gauge being registered
     private final ConcurrentHashMap<MailQueueName, RabbitMQMailQueue> instanciatedQueues;
@@ -42,10 +97,10 @@ public class RabbitMQMailQueueFactory implements MailQueueFactory<RabbitMQMailQu
     @Inject
     RabbitMQMailQueueFactory(RabbitClient rabbitClient,
                              RabbitMQManagementApi mqManagementApi,
-                             RabbitMQMailQueue.Factory mailQueueFactory) {
+                             PrivateFactory privateFactory) {
         this.rabbitClient = rabbitClient;
         this.mqManagementApi = mqManagementApi;
-        this.mailQueueFactory = mailQueueFactory;
+        this.privateFactory = privateFactory;
         this.instanciatedQueues = new ConcurrentHashMap<>();
     }
 
@@ -81,6 +136,6 @@ public class RabbitMQMailQueueFactory implements MailQueueFactory<RabbitMQMailQu
     }
 
     private RabbitMQMailQueue getOrElseCreateLocally(MailQueueName name) {
-        return instanciatedQueues.computeIfAbsent(name, mailQueueFactory::create);
+        return instanciatedQueues.computeIfAbsent(name, privateFactory::create);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/4889416c/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
index 2d7c2b9..a1f9ba4 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
@@ -129,7 +129,7 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
                 new AsyncRetryExecutor(Executors.newSingleThreadScheduledExecutor()));
 
         RabbitClient rabbitClient = new RabbitClient(new RabbitChannelPool(rabbitMQConnectionFactory));
-        RabbitMQMailQueue.Factory factory = new RabbitMQMailQueue.Factory(
+        RabbitMQMailQueueFactory.PrivateFactory factory = new RabbitMQMailQueueFactory.PrivateFactory(
             metricTestSystem.getSpyMetricFactory(),
             metricTestSystem.getSpyGaugeRegistry(),
             rabbitClient,

http://git-wip-us.apache.org/repos/asf/james-project/blob/4889416c/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
index 0a1e7d1..55a5ec8 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
@@ -76,7 +76,7 @@ class RabbitMqMailQueueFactoryTest implements MailQueueFactoryContract<RabbitMQM
             new AsyncRetryExecutor(Executors.newSingleThreadScheduledExecutor()));
 
         RabbitClient rabbitClient = new RabbitClient(new RabbitChannelPool(rabbitMQConnectionFactory));
-        RabbitMQMailQueue.Factory factory = new RabbitMQMailQueue.Factory(
+        RabbitMQMailQueueFactory.PrivateFactory factory = new RabbitMQMailQueueFactory.PrivateFactory(
             new NoopMetricFactory(),
             new NoopGaugeRegistry(),
             rabbitClient,


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