[Notice] Announcing the End of Demo Server [Read me]
doortts doortts 2018-02-26
mailbox: call by async when to start Mailbox service
It may reduce starting up time of Yona.

See: Yona Github issue #317
@bf210022e28875908847fb1a4235f064cedf4564
app/mailbox/MailboxService.java
--- app/mailbox/MailboxService.java
+++ app/mailbox/MailboxService.java
@@ -1,23 +1,10 @@
 /**
- * Yobi, Project Hosting SW
- *
- * Copyright 2014 NAVER Corp.
- * http://yobi.io
- *
- * @Author Yi EungJun
- *
- * Licensed 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.
- */
+ * Yona, 21st Century Project Hosting SW
+ * <p>
+ * Copyright Yona & Yobi Authors & NAVER Corp. & NAVER LABS Corp.
+ * https://yona.io
+ **/
+
 package mailbox;
 
 import akka.actor.Cancellable;
@@ -29,6 +16,7 @@
 import play.Configuration;
 import play.Logger;
 import play.libs.Akka;
+import play.libs.F;
 import scala.concurrent.duration.Duration;
 import utils.Diagnostic;
 import utils.SimpleDiagnostic;
@@ -184,17 +172,7 @@
             return;
         }
 
-        try {
-            EmailHandler.handleNewMessages(folder);
-        } catch (MessagingException e) {
-            play.Logger.error("Failed to handle new messages");
-        }
-
-        try {
-            startEmailListener();
-        } catch (Exception e) {
-            startEmailPolling();
-        }
+        handleNewMessagesAndStartListener();
 
         Diagnostic.register(new SimpleDiagnostic() {
             @Override
@@ -210,6 +188,27 @@
         });
     }
 
+    private void handleNewMessagesAndStartListener() {
+        F.Promise<Void> promise = F.Promise.promise(
+                new F.Function0<Void>() {
+                    public Void apply() {
+                        try {
+                            EmailHandler.handleNewMessages(folder);
+                        } catch (MessagingException e) {
+                            Logger.error("Failed to handle new messages");
+                        }
+
+                        try {
+                            startEmailListener();
+                        } catch (Exception e) {
+                            startEmailPolling();
+                        }
+                        return null;
+                    }
+                }
+        );
+    }
+
     /**
      * Reopen the IMAP folder which is used by MailboxService.
      *
Add a comment
List