You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2021/03/03 07:07:09 UTC

[james-project] 01/23: JAMES-3505 Make mail delivery multi-threaded

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 ce3c957f223ac47ce72b044069d9ebb9c1a4d925
Author: brokenshoebox <br...@gmail.com>
AuthorDate: Mon Mar 1 12:00:02 2021 +1300

    JAMES-3505 Make mail delivery multi-threaded
    
    Mail delivery is single threaded due to blocking code in
    DeliveryRunnable, which prevents reactor from scheduling mails
    simultaneously.
---
 .../mailets/remote/delivery/DeliveryRunnable.java  | 43 +++++++++++++---------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/DeliveryRunnable.java b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/DeliveryRunnable.java
index f380632..d708f2e 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/DeliveryRunnable.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remote/delivery/DeliveryRunnable.java
@@ -104,24 +104,31 @@ public class DeliveryRunnable implements Disposable {
         }
     }
 
-    private Mono<Void> processMail(MailQueue.MailQueueItem queueItem) throws MailQueue.MailQueueException {
-        Mail mail = queueItem.getMail();
-
-        try {
-            LOGGER.debug("will process mail {}", mail.getName());
-            attemptDelivery(mail);
-            queueItem.done(true);
-            return Mono.empty();
-        } catch (Exception e) {
-            // Prevent unexpected exceptions from causing looping by removing message from outgoing.
-            // DO NOT CHANGE THIS to catch Error!
-            // For example, if there were an OutOfMemory condition caused because
-            // something else in the server was abusing memory, we would not want to start purging the retrying spool!
-            queueItem.done(false);
-            return Mono.error(e);
-        } finally {
-            LifecycleUtil.dispose(mail);
-        }
+    private Mono<Void> processMail(MailQueue.MailQueueItem queueItem) {
+        return Mono.create(sink -> {
+            Mail mail = queueItem.getMail();
+
+            try {
+                LOGGER.debug("will process mail {}", mail.getName());
+                attemptDelivery(mail);
+                queueItem.done(true);
+                sink.success();
+            } catch (Exception e) {
+                try {
+                    // Prevent unexpected exceptions from causing looping by removing message from outgoing.
+                    // DO NOT CHANGE THIS to catch Error!
+                    // For example, if there were an OutOfMemory condition caused because
+                    // something else in the server was abusing memory, we would not want to start purging the retrying spool!
+                    queueItem.done(false);
+                } catch (Exception ex) {
+                    sink.error(ex);
+                    return;
+                }
+                sink.error(e);
+            } finally {
+                LifecycleUtil.dispose(mail);
+            }
+        });
     }
 
     @VisibleForTesting


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org