| 37477 |
amit |
1 |
package com.spice.profitmandi.common.mail;
|
|
|
2 |
|
|
|
3 |
import org.apache.logging.log4j.LogManager;
|
|
|
4 |
import org.apache.logging.log4j.Logger;
|
|
|
5 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
6 |
import org.springframework.stereotype.Component;
|
|
|
7 |
|
|
|
8 |
/**
|
|
|
9 |
* Bridges the static mail helpers in Utils to the Spring-managed {@link MailQueue}.
|
|
|
10 |
*
|
|
|
11 |
* This is a deliberate compromise, not a pattern to copy. Utils.sendMail* are
|
|
|
12 |
* static and called from 27 places, several of them static contexts that have no
|
|
|
13 |
* bean to inject into. Converting all of them at once would be a large,
|
|
|
14 |
* mechanical, and risky change to code paths that send real money-related
|
|
|
15 |
* reports. Holding the queue in one place instead lets those helpers stop
|
|
|
16 |
* sending inline today, and lets the call sites move at their own pace.
|
|
|
17 |
*
|
|
|
18 |
* New code must inject {@link MailQueue} directly. Nothing except Utils should
|
|
|
19 |
* read this.
|
|
|
20 |
*/
|
|
|
21 |
@Component
|
|
|
22 |
public final class MailQueueHolder {
|
|
|
23 |
|
|
|
24 |
private static final Logger LOGGER = LogManager.getLogger(MailQueueHolder.class);
|
|
|
25 |
|
|
|
26 |
private static volatile MailQueue mailQueue;
|
|
|
27 |
|
|
|
28 |
@Autowired
|
|
|
29 |
public void setMailQueue(MailQueue queue) {
|
|
|
30 |
mailQueue = queue;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Returns null before the context has finished starting. Callers must handle
|
|
|
35 |
* that rather than assume — a mail sent during startup is better dropped with
|
|
|
36 |
* a log line than allowed to NPE inside a scheduled job.
|
|
|
37 |
*/
|
|
|
38 |
public static MailQueue get() {
|
|
|
39 |
if (mailQueue == null) {
|
|
|
40 |
LOGGER.warn("MailQueue requested before the Spring context supplied one; mail dropped");
|
|
|
41 |
}
|
|
|
42 |
return mailQueue;
|
|
|
43 |
}
|
|
|
44 |
}
|