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 16617ab9ecdff41181c18c71e14f37d58d1b8b9b Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Tue Jun 25 08:28:36 2019 +0700 JAMES-2794 Replace a pair by MailWithEnqueueId --- .../org/apache/james/queue/rabbitmq/Dequeuer.java | 24 ++++++------- .../apache/james/queue/rabbitmq/MailLoader.java | 5 ++- .../james/queue/rabbitmq/MailWithEnqueueId.java | 40 ++++++++++++++++++++++ .../queue/rabbitmq/RabbitMQMailQueueFactory.java | 4 +-- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/Dequeuer.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/Dequeuer.java index 01db228..94b803c 100644 --- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/Dequeuer.java +++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/Dequeuer.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.util.function.Consumer; import java.util.function.Function; -import org.apache.commons.lang3.tuple.Pair; import org.apache.james.metrics.api.Metric; import org.apache.james.metrics.api.MetricFactory; import org.apache.james.queue.api.MailQueue; @@ -50,10 +49,10 @@ class Dequeuer { private final EnqueueId enqueueId; private final Mail mail; - private RabbitMQMailQueueItem(Consumer<Boolean> ack, EnqueueId enqueueId, Mail mail) { + private RabbitMQMailQueueItem(Consumer<Boolean> ack, MailWithEnqueueId mailWithEnqueueId) { this.ack = ack; - this.enqueueId = enqueueId; - this.mail = mail; + this.enqueueId = mailWithEnqueueId.getEnqueueId(); + this.mail = mailWithEnqueueId.getMail(); } @Override @@ -71,12 +70,12 @@ class Dequeuer { } } - private final Function<MailReferenceDTO, Pair<EnqueueId, Mail>> mailLoader; + private final Function<MailReferenceDTO, MailWithEnqueueId> mailLoader; private final Metric dequeueMetric; private final MailReferenceSerializer mailReferenceSerializer; private final MailQueueView mailQueueView; - Dequeuer(MailQueueName name, RabbitClient rabbitClient, Function<MailReferenceDTO, Pair<EnqueueId, Mail>> mailLoader, + Dequeuer(MailQueueName name, RabbitClient rabbitClient, Function<MailReferenceDTO, MailWithEnqueueId> mailLoader, MailReferenceSerializer serializer, MetricFactory metricFactory, MailQueueView mailQueueView) { this.mailLoader = mailLoader; @@ -108,28 +107,27 @@ class Dequeuer { private Mono<RabbitMQMailQueueItem> loadItem(AcknowledgableDelivery response) { try { - Pair<EnqueueId, Mail> idAndMail = loadMail(response); - Mail mail = idAndMail.getRight(); - ThrowingConsumer<Boolean> ack = ack(response, mail); - return Mono.just(new RabbitMQMailQueueItem(ack, idAndMail.getLeft(), mail)); + MailWithEnqueueId mailWithEnqueueId = loadMail(response); + ThrowingConsumer<Boolean> ack = ack(response, mailWithEnqueueId); + return Mono.just(new RabbitMQMailQueueItem(ack, mailWithEnqueueId)); } catch (MailQueue.MailQueueException e) { return Mono.error(e); } } - private ThrowingConsumer<Boolean> ack(AcknowledgableDelivery response, Mail mail) { + private ThrowingConsumer<Boolean> ack(AcknowledgableDelivery response, MailWithEnqueueId mailWithEnqueueId) { return success -> { if (success) { dequeueMetric.increment(); response.ack(); - mailQueueView.delete(DeleteCondition.withName(mail.getName())); + mailQueueView.delete(DeleteCondition.withName(mailWithEnqueueId.getMail().getName())); } else { response.nack(REQUEUE); } }; } - private Pair<EnqueueId, Mail> loadMail(Delivery response) throws MailQueue.MailQueueException { + private MailWithEnqueueId loadMail(Delivery response) throws MailQueue.MailQueueException { MailReferenceDTO mailDTO = toMailReference(response); return mailLoader.apply(mailDTO); } diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailLoader.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailLoader.java index 98fdc5c..a616909 100644 --- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailLoader.java +++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailLoader.java @@ -23,7 +23,6 @@ import javax.mail.MessagingException; import javax.mail.internet.AddressException; import javax.mail.internet.MimeMessage; -import org.apache.commons.lang3.tuple.Pair; import org.apache.james.blob.api.BlobId; import org.apache.james.blob.api.Store; import org.apache.james.blob.mail.MimeMessagePartsId; @@ -39,14 +38,14 @@ class MailLoader { this.blobIdFactory = blobIdFactory; } - Pair<EnqueueId, Mail> load(MailReferenceDTO dto) throws MailQueue.MailQueueException { + MailWithEnqueueId load(MailReferenceDTO dto) throws MailQueue.MailQueueException { try { MailReference mailReference = dto.toMailReference(blobIdFactory); Mail mail = mailReference.getMail(); MimeMessage mimeMessage = mimeMessageStore.read(mailReference.getPartsId()).block(); mail.setMessage(mimeMessage); - return Pair.of(mailReference.getEnqueueId(), mail); + return new MailWithEnqueueId(mailReference.getEnqueueId(), mail); } catch (AddressException e) { throw new MailQueue.MailQueueException("Failed to parse mail address", e); } catch (MessagingException e) { diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailWithEnqueueId.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailWithEnqueueId.java new file mode 100644 index 0000000..f256fbf --- /dev/null +++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/MailWithEnqueueId.java @@ -0,0 +1,40 @@ +/**************************************************************** + * 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.queue.rabbitmq; + +import org.apache.mailet.Mail; + +public class MailWithEnqueueId { + private final EnqueueId enqueueId; + private final Mail mail; + + MailWithEnqueueId(EnqueueId enqueueId, Mail mail) { + this.enqueueId = enqueueId; + this.mail = mail; + } + + public EnqueueId getEnqueueId() { + return enqueueId; + } + + public Mail getMail() { + return mail; + } +} 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 fdf24a1..adaf3de 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 @@ -30,7 +30,6 @@ import java.util.function.Function; import javax.inject.Inject; import javax.mail.internet.MimeMessage; -import org.apache.commons.lang3.tuple.Pair; import org.apache.james.blob.api.BlobId; import org.apache.james.blob.api.Store; import org.apache.james.blob.mail.MimeMessagePartsId; @@ -40,7 +39,6 @@ import org.apache.james.metrics.api.MetricFactory; import org.apache.james.queue.api.MailQueueFactory; import org.apache.james.queue.api.MailQueueItemDecoratorFactory; 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; @@ -54,7 +52,7 @@ public class RabbitMQMailQueueFactory implements MailQueueFactory<RabbitMQMailQu private final RabbitClient rabbitClient; private final Store<MimeMessage, MimeMessagePartsId> mimeMessageStore; private final MailReferenceSerializer mailReferenceSerializer; - private final Function<MailReferenceDTO, Pair<EnqueueId, Mail>> mailLoader; + private final Function<MailReferenceDTO, MailWithEnqueueId> mailLoader; private final MailQueueView.Factory mailQueueViewFactory; private final Clock clock; private final MailQueueItemDecoratorFactory decoratorFactory; --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org