[Notice] Announcing the End of Demo Server [Read me]
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
... | ... | @@ -1,23 +1,10 @@ |
1 | 1 |
/** |
2 |
- * Yobi, Project Hosting SW |
|
3 |
- * |
|
4 |
- * Copyright 2014 NAVER Corp. |
|
5 |
- * http://yobi.io |
|
6 |
- * |
|
7 |
- * @Author Yi EungJun |
|
8 |
- * |
|
9 |
- * Licensed under the Apache License, Version 2.0 (the "License"); |
|
10 |
- * you may not use this file except in compliance with the License. |
|
11 |
- * You may obtain a copy of the License at |
|
12 |
- * |
|
13 |
- * http://www.apache.org/licenses/LICENSE-2.0 |
|
14 |
- * |
|
15 |
- * Unless required by applicable law or agreed to in writing, software |
|
16 |
- * distributed under the License is distributed on an "AS IS" BASIS, |
|
17 |
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
18 |
- * See the License for the specific language governing permissions and |
|
19 |
- * limitations under the License. |
|
20 |
- */ |
|
2 |
+ * Yona, 21st Century Project Hosting SW |
|
3 |
+ * <p> |
|
4 |
+ * Copyright Yona & Yobi Authors & NAVER Corp. & NAVER LABS Corp. |
|
5 |
+ * https://yona.io |
|
6 |
+ **/ |
|
7 |
+ |
|
21 | 8 |
package mailbox; |
22 | 9 |
|
23 | 10 |
import akka.actor.Cancellable; |
... | ... | @@ -29,6 +16,7 @@ |
29 | 16 |
import play.Configuration; |
30 | 17 |
import play.Logger; |
31 | 18 |
import play.libs.Akka; |
19 |
+import play.libs.F; |
|
32 | 20 |
import scala.concurrent.duration.Duration; |
33 | 21 |
import utils.Diagnostic; |
34 | 22 |
import utils.SimpleDiagnostic; |
... | ... | @@ -184,17 +172,7 @@ |
184 | 172 |
return; |
185 | 173 |
} |
186 | 174 |
|
187 |
- try { |
|
188 |
- EmailHandler.handleNewMessages(folder); |
|
189 |
- } catch (MessagingException e) { |
|
190 |
- play.Logger.error("Failed to handle new messages"); |
|
191 |
- } |
|
192 |
- |
|
193 |
- try { |
|
194 |
- startEmailListener(); |
|
195 |
- } catch (Exception e) { |
|
196 |
- startEmailPolling(); |
|
197 |
- } |
|
175 |
+ handleNewMessagesAndStartListener(); |
|
198 | 176 |
|
199 | 177 |
Diagnostic.register(new SimpleDiagnostic() { |
200 | 178 |
@Override |
... | ... | @@ -210,6 +188,27 @@ |
210 | 188 |
}); |
211 | 189 |
} |
212 | 190 |
|
191 |
+ private void handleNewMessagesAndStartListener() { |
|
192 |
+ F.Promise<Void> promise = F.Promise.promise( |
|
193 |
+ new F.Function0<Void>() { |
|
194 |
+ public Void apply() { |
|
195 |
+ try { |
|
196 |
+ EmailHandler.handleNewMessages(folder); |
|
197 |
+ } catch (MessagingException e) { |
|
198 |
+ Logger.error("Failed to handle new messages"); |
|
199 |
+ } |
|
200 |
+ |
|
201 |
+ try { |
|
202 |
+ startEmailListener(); |
|
203 |
+ } catch (Exception e) { |
|
204 |
+ startEmailPolling(); |
|
205 |
+ } |
|
206 |
+ return null; |
|
207 |
+ } |
|
208 |
+ } |
|
209 |
+ ); |
|
210 |
+ } |
|
211 |
+ |
|
213 | 212 |
/** |
214 | 213 |
* Reopen the IMAP folder which is used by MailboxService. |
215 | 214 |
* |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?